From d84f2ed22ead1fe9c54782c7e5c693db2451a4a3 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Wed, 9 Feb 2022 20:08:44 +0100 Subject: [PATCH] Issue #1529: detect klink.exe and putty.exe as variants of plink executable --- source/apphelpers.pas | 17 +++++++++++++++++ source/dbconnection.pas | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/source/apphelpers.pas b/source/apphelpers.pas index 03238a66..fd8d020f 100644 --- a/source/apphelpers.pas +++ b/source/apphelpers.pas @@ -310,6 +310,7 @@ type function getFirstWord(text: String; MustStartWithWordChar: Boolean=True): String; function RegExprGetMatch(Expression: String; var Input: String; ReturnMatchNum: Integer; DeleteFromSource, CaseInsensitive: Boolean): String; Overload; function RegExprGetMatch(Expression: String; Input: String; ReturnMatchNum: Integer): String; Overload; + function ExecRegExprI(const ARegExpr, AInputStr: RegExprString): Boolean; function FormatByteNumber( Bytes: Int64; Decimals: Byte = 1 ): String; Overload; function FormatByteNumber( Bytes: String; Decimals: Byte = 1 ): String; Overload; function FormatTimeNumber(Seconds: Double; DisplaySeconds: Boolean): String; @@ -1021,6 +1022,22 @@ begin end; +function ExecRegExprI(const ARegExpr, AInputStr: RegExprString): Boolean; +var + r: TRegExpr; +begin + Result := False; + r := TRegExpr.Create; + r.ModifierI := True; + try + r.Expression := ARegExpr; + Result := r.Exec(AInputStr); + finally + r.Free; + end; +end; + + {** Format a filesize to automatically use the best fitting expression 16 100 000 Bytes -> 16,1 MB diff --git a/source/dbconnection.pas b/source/dbconnection.pas index 5996edd8..c2e21f8a 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -1085,7 +1085,7 @@ begin // Build SSH command line // plink bob@domain.com -pw myPassw0rd1 -P 22 -i "keyfile.pem" -L 55555:localhost:3306 - IsPlink := FConnection.Parameters.SSHExe.ToLowerInvariant.Contains('plink'); + IsPlink := ExecRegExprI('([pk]link|putty)', FConnection.Parameters.SSHExe); SshCmd := FConnection.Parameters.SSHExe; if IsPlink then SshCmd := SshCmd + ' -ssh';