From e1e62711095668800890cdb61e9e26afcd098de3 Mon Sep 17 00:00:00 2001 From: Ragnar Thomsen Date: Tue, 19 Jul 2016 22:09:38 +0200 Subject: [PATCH] Fix testing encrypted archives for integrity Enable testing of encrypted archives by passing the password switch to the cli programs. When we don't know the password we disable the Test action with an explanation in the tooltip. Differential Revision: D2227 --- kerfuffle/cliinterface.cpp | 11 ++++++++--- kerfuffle/cliinterface.h | 2 +- part/part.cpp | 6 +++++- plugins/cli7zplugin/cliplugin.cpp | 3 ++- plugins/clirarplugin/cliplugin.cpp | 3 ++- plugins/clizipplugin/cliplugin.cpp | 3 ++- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/kerfuffle/cliinterface.cpp b/kerfuffle/cliinterface.cpp index f72b3ea9..9f445f86 100644 --- a/kerfuffle/cliinterface.cpp +++ b/kerfuffle/cliinterface.cpp @@ -222,7 +222,7 @@ bool CliInterface::testArchive() cacheParameterList(); m_operationMode = Test; - const auto args = substituteTestVariables(m_param.value(TestArgs).toStringList()); + const auto args = substituteTestVariables(m_param.value(TestArgs).toStringList(), password()); if (!runProcess(m_param.value(TestProgram).toStringList(), args)) { return false; @@ -739,7 +739,7 @@ QStringList CliInterface::substituteCommentVariables(const QStringList &commentA return args; } -QStringList CliInterface::substituteTestVariables(const QStringList &testArgs) +QStringList CliInterface::substituteTestVariables(const QStringList &testArgs, const QString &password) { // Required if we call this function from unit tests. cacheParameterList(); @@ -753,6 +753,11 @@ QStringList CliInterface::substituteTestVariables(const QStringList &testArgs) continue; } + if (arg == QLatin1String("$PasswordSwitch")) { + args << passwordSwitch(password); + continue; + } + args << arg; } @@ -1072,7 +1077,7 @@ void CliInterface::handleLine(const QString& line) if (checkForPasswordPromptMessage(line)) { qCDebug(ARK) << "Found a password prompt"; - emit error(i18n("Ark does not currently support testing password-protected archives.")); + emit error(i18n("Ark does not currently support testing this archive.")); killProcess(); return; } diff --git a/kerfuffle/cliinterface.h b/kerfuffle/cliinterface.h index 2aae7c61..de97c691 100644 --- a/kerfuffle/cliinterface.h +++ b/kerfuffle/cliinterface.h @@ -313,7 +313,7 @@ public: QStringList substituteAddVariables(const QStringList &addArgs, const QStringList &files, const QString &password, bool encryptHeader, int compLevel); QStringList substituteDeleteVariables(const QStringList &deleteArgs, const QVariantList &files, const QString &password); QStringList substituteCommentVariables(const QStringList &commentArgs, const QString &commentFile); - QStringList substituteTestVariables(const QStringList &testArgs); + QStringList substituteTestVariables(const QStringList &testArgs, const QString &password); /** * @return The preserve path switch, according to the @p preservePaths extraction option. diff --git a/part/part.cpp b/part/part.cpp index 8fa4564a..b6784105 100644 --- a/part/part.cpp +++ b/part/part.cpp @@ -425,8 +425,11 @@ void Part::updateActions() m_addFilesAction->setToolTip(xi18nc("@info:tooltip", "Adding files to existing password-protected archives with no header-encryption is currently not supported." "Extract the files and create a new archive if you want to add files.")); + m_testArchiveAction->setToolTip(xi18nc("@info:tooltip", + "Testing password-protected archives with no header-encryption is currently not supported.")); } else { m_addFilesAction->setToolTip(i18nc("@info:tooltip", "Click to add files to the archive")); + m_testArchiveAction->setToolTip(i18nc("@info:tooltip", "Click to test the archive for integrity")); } // Figure out if entry size is larger than preview size limit. @@ -479,7 +482,8 @@ void Part::updateActions() bool supportsTesting = ArchiveFormat::fromMetadata(m_model->archive()->mimeType(), metadata).supportsTesting(); m_testArchiveAction->setEnabled(!isBusy() && - supportsTesting); + supportsTesting && + !isEncryptedButUnknownPassword); } else { m_commentView->setReadOnly(true); m_editCommentAction->setText(i18nc("@action:inmenu mutually exclusive with Edit &Comment", "Add &Comment")); diff --git a/plugins/cli7zplugin/cliplugin.cpp b/plugins/cli7zplugin/cliplugin.cpp index 5be07d52..0e9f7d29 100644 --- a/plugins/cli7zplugin/cliplugin.cpp +++ b/plugins/cli7zplugin/cliplugin.cpp @@ -85,7 +85,8 @@ ParameterList CliPlugin::parameterList() const << QStringLiteral("$Archive") << QStringLiteral("$Files"); p[TestArgs] = QStringList() << QStringLiteral("t") - << QStringLiteral("$Archive"); + << QStringLiteral("$Archive") + << QStringLiteral("$PasswordSwitch"); p[TestPassedPattern] = QStringLiteral("^Everything is Ok$"); p[FileExistsExpression] = QStringList() diff --git a/plugins/clirarplugin/cliplugin.cpp b/plugins/clirarplugin/cliplugin.cpp index 0558623e..68a21a4b 100644 --- a/plugins/clirarplugin/cliplugin.cpp +++ b/plugins/clirarplugin/cliplugin.cpp @@ -125,7 +125,8 @@ ParameterList CliPlugin::parameterList() const << QStringLiteral("$Archive"); p[CommentSwitch] = QStringLiteral("-z$CommentFile"); p[TestArgs] = QStringList() << QStringLiteral("t") - << QStringLiteral("$Archive"); + << QStringLiteral("$Archive") + << QStringLiteral("$PasswordSwitch"); p[TestPassedPattern] = QStringLiteral("^All OK$"); } diff --git a/plugins/clizipplugin/cliplugin.cpp b/plugins/clizipplugin/cliplugin.cpp index ea2f6d23..eeb6b40c 100644 --- a/plugins/clizipplugin/cliplugin.cpp +++ b/plugins/clizipplugin/cliplugin.cpp @@ -123,7 +123,8 @@ ParameterList CliPlugin::parameterList() const p[DiskFullPatterns] = QStringList() << QStringLiteral("write error \\(disk full\\?\\)") << QStringLiteral("No space left on device"); p[TestArgs] = QStringList() << QStringLiteral("-t") - << QStringLiteral("$Archive"); + << QStringLiteral("$Archive") + << QStringLiteral("$PasswordSwitch"); p[TestPassedPattern] = QStringLiteral("^No errors detected in compressed data of "); } return p; -- GitLab