diff --git a/src/main.cpp b/src/main.cpp --- a/src/main.cpp +++ b/src/main.cpp @@ -40,46 +40,55 @@ // has no i18n, so this should work for all languages as long as the string is unchanged. static void parsePrompt(const QString &prompt, QString& keyFile, bool& wrongPassphrase) { - // Case 1: asking for passphrase for a certain keyfile for the first time => we should try a password from the wallet - QRegularExpression re1("^Enter passphrase for (.*?)( \\(will confirm each use\\))?: $"); - QRegularExpressionMatch match1 = re1.match(prompt); - if (match1.hasMatch()) { - keyFile = match1.captured(1); - wrongPassphrase = false; - return; - } + // Case 1: asking for passphrase for a certain keyfile for the first time => we should try a password from the wallet + QRegularExpression re1("^Enter passphrase for (.*?)( \\(will confirm each use\\))?: $"); + QRegularExpressionMatch match1 = re1.match(prompt); + if (match1.hasMatch()) { + keyFile = match1.captured(1); + wrongPassphrase = false; + return; + } - // Case 2: re-asking for passphrase for a certain keyfile => probably we've tried a password from the wallet, no point - // in trying it again - QRegularExpression re2("^Bad passphrase, try again for (.*?)( \\(will confirm each use\\))?: $"); - QRegularExpressionMatch match2 = re2.match(prompt); - if (match2.hasMatch()) { - keyFile = match2.captured(1); - wrongPassphrase = true; - return; - } + // Case 2: re-asking for passphrase for a certain keyfile => probably we've tried a password from the wallet, no point + // in trying it again + QRegularExpression re2("^Bad passphrase, try again for (.*?)( \\(will confirm each use\\))?: $"); + QRegularExpressionMatch match2 = re2.match(prompt); + if (match2.hasMatch()) { + keyFile = match2.captured(1); + wrongPassphrase = true; + return; + } + + //Case 3: Fix password extraction from git. bug number 376228 + QRegularExpression re3("^(Password|Username) for (.*?)[:] $"); + QRegularExpressionMatch match3 = re3.match(prompt); + if (match3.hasMatch()) { + keyFile = match3.captured(2); + wrongPassphrase = false; + return; + } - // Case 3: nothing matched; either it was called by some sort of a script with a custom prompt (i.e. not ssh-add), or - // strings we're looking for were broken. Issue a warning and continue without keyFile. - qCWarning(LOG_KSSHASKPASS) << "Unable to extract keyFile from phrase" << prompt; + // Case 4: nothing matched; either it was called by some sort of a script with a custom prompt (i.e. not ssh-add), or + // strings we're looking for were broken. Issue a warning and continue without keyFile. + qCWarning(LOG_KSSHASKPASS) << "Unable to extract keyFile from phrase" << prompt; } int main(int argc, char **argv) { KLocalizedString::setApplicationDomain("ksshaskpass"); //TODO update it. KAboutData about( - QStringLiteral("ksshaskpass"), - i18n("Ksshaskpass"), - PROJECT_VERSION, - i18n("KDE version of ssh-askpass"), - KAboutLicense::GPL, - i18n("(c) 2006 Hans van Leeuwen\n(c) 2008-2010 Armin Berres"), - i18n("Ksshaskpass allows you to interactively prompt users for a passphrase for ssh-add"), - QStringLiteral("http://www.kde-apps.org/content/show.php?action=content&content=50971"), - QStringLiteral("armin@space-based.de") - ); + QStringLiteral("ksshaskpass"), + i18n("Ksshaskpass"), + PROJECT_VERSION, + i18n("KDE version of ssh-askpass"), + KAboutLicense::GPL, + i18n("(c) 2006 Hans van Leeuwen\n(c) 2008-2010 Armin Berres"), + i18n("Ksshaskpass allows you to interactively prompt users for a passphrase for ssh-add"), + QStringLiteral("http://www.kde-apps.org/content/show.php?action=content&content=50971"), + QStringLiteral("armin@space-based.de") + ); about.addAuthor(i18n("Armin Berres"), i18n("Current author"), QStringLiteral("armin@space-based.de"), 0); about.addAuthor(i18n("Hans van Leeuwen"), i18n("Original author"), QStringLiteral("hanz@hanz.nl"), 0);