Skip to content
Permalink
Browse files

Add cleartext option to sessions

  • Loading branch information...
chadwhitely authored and ansgarbecker committed Jun 11, 2019
1 parent 6641b82 commit 0facfaa5cc28c20c3d570964b531cc2cd51ca663
Showing with 60 additions and 22 deletions.
  1. +5 −0 out/locale/en/LC_MESSAGES/default.po
  2. +6 −2 source/apphelpers.pas
  3. +13 −0 source/connections.dfm
  4. +8 −1 source/connections.pas
  5. +28 −19 source/dbconnection.pas
@@ -340,6 +340,11 @@ msgstr "Prompt for credentials"
msgid "Use Windows authentication"
msgstr "Use Windows authentication"

#. connform..PageControlDetails..tabSettings..chkCleartextPluginEnabled..Caption
#: connections.dfm:737
msgid "Use cleartext plugin"
msgstr "Use cleartext plugin"

#. connform..PageControlDetails..tabSettings..chkLocalTimeZone....Hint
#: connections.dfm:406
msgid "Use your client time zone in date/time SQL functions, e.g. NOW(), for MySQL 4.1.3+"
@@ -141,7 +141,7 @@ TQueryThread = class(TThread)
asWrapLongLines, asDisplayBLOBsAsText, asSingleQueries, asMemoEditorWidth, asMemoEditorHeight, asMemoEditorMaximized,
asMemoEditorWrap, asDelimiter, asSQLHelpWindowLeft, asSQLHelpWindowTop, asSQLHelpWindowWidth,
asSQLHelpWindowHeight, asSQLHelpPnlLeftWidth, asSQLHelpPnlRightTopHeight, asHost,
asUser, asPassword, asWindowsAuth, asLoginPrompt, asPort,
asUser, asPassword, asCleartextPluginEnabled, asWindowsAuth, asLoginPrompt, asPort,
asPlinkExecutable, asSSHtunnelHost, asSSHtunnelHostPort, asSSHtunnelPort, asSSHtunnelUser,
asSSHtunnelPassword, asSSHtunnelTimeout, asSSHtunnelPrivateKey, asSSLActive, asSSLKey,
asSSLCert, asSSLCA, asSSLCipher, asNetType, asCompressed, asLocalTimeZone, asQueryTimeout, asKeepAlive,
@@ -2627,7 +2627,7 @@ procedure ParseCommandLine(CommandLine: String; var ConnectionParams: TConnectio
rx: TRegExpr;
ExeName, SessName, Host, User, Pass, Socket,
SSLPrivateKey, SSLCACertificate, SSLCertificate, SSLCipher: String;
Port, NetType, WindowsAuth, WantSSL: Integer;
Port, NetType, WindowsAuth, WantSSL, CleartextPluginEnabled: Integer;
AbsentFiles: TStringList;

function GetParamValue(ShortName, LongName: String): String;
@@ -2692,6 +2692,7 @@ procedure ParseCommandLine(CommandLine: String; var ConnectionParams: TConnectio
Host := GetParamValue('h', 'host');
User := GetParamValue('u', 'user');
Pass := GetParamValue('p', 'password');
CleartextPluginEnabled := StrToIntDef(GetParamValue('cleartextenabled', 'cleartextenabled'), -1);
Socket := GetParamValue('S', 'socket');
Port := StrToIntDef(GetParamValue('P', 'port'), 0);
WindowsAuth := StrToIntDef(GetParamValue('W', 'winauth'), -1);
@@ -2716,6 +2717,8 @@ procedure ParseCommandLine(CommandLine: String; var ConnectionParams: TConnectio
if Host <> '' then ConnectionParams.Hostname := Host;
if User <> '' then ConnectionParams.Username := User;
if Pass <> '' then ConnectionParams.Password := Pass;
if CleartextPluginEnabled in [0,1] then
ConnectionParams.CleartextPluginEnabled := Boolean(CleartextPluginEnabled);
if Port <> 0 then ConnectionParams.Port := Port;
if Socket <> '' then begin
ConnectionParams.Hostname := Socket;
@@ -3521,6 +3524,7 @@ constructor TAppSettings.Create;
InitSetting(asHost, 'Host', 0, False, '127.0.0.1', True);
InitSetting(asUser, 'User', 0, False, '', True);
InitSetting(asPassword, 'Password', 0, False, '', True);
InitSetting(asCleartextPluginEnabled, 'CleartextPluginEnabled' 0, False, '', True);
InitSetting(asWindowsAuth, 'WindowsAuth', 0, False, '', True);
InitSetting(asLoginPrompt, 'LoginPrompt', 0, False, '', True);
InitSetting(asPort, 'Port', 0, False, '', True);
@@ -734,6 +734,19 @@ object connform: Tconnform
TabOrder = 8
OnClick = Modification
end
object chkCleartextPluginEnabled: TCheckBox
Left = 120
Top = 329
Width = 294
Height = 17
Hint =
'Send your password to the server in cleartext' +
', for MySQL 5.5.47+'
Anchors = [akLeft, akTop, akRight]
Caption = 'Use cleartext plugin'
TabOrder = 13
OnClick = Modification
end
object editStartupScript: TButtonedEdit
Left = 120
Top = 165
@@ -76,6 +76,7 @@ Tconnform = class(TFormWithSizeGrip)
editSSHTimeout: TEdit;
updownSSHTimeout: TUpDown;
chkWindowsAuth: TCheckBox;
chkCleartextPluginEnabled: TCheckBox;
splitterMain: TSplitter;
tabStart: TTabSheet;
lblHelp: TLabel;
@@ -378,6 +379,7 @@ procedure Tconnform.btnSaveClick(Sender: TObject);
Sess.Password := editPassword.Text;
Sess.LoginPrompt := chkLoginPrompt.Checked;
Sess.WindowsAuth := chkWindowsAuth.Checked;
Sess.CleartextPluginEnabled := chkCleartextPluginEnabled.Checked;
Sess.Port := updownPort.Position;
Sess.NetType := TNetType(comboNetType.ItemIndex);
Sess.Compressed := chkCompressed.Checked;
@@ -574,6 +576,7 @@ function Tconnform.CurrentParams: TConnectionParameters;
Result.Password := editPassword.Text;
Result.LoginPrompt := chkLoginPrompt.Checked;
Result.WindowsAuth := chkWindowsAuth.Checked;
Result.CleartextPluginEnabled := chkCleartextPluginEnabled.Checked;
if updownPort.Enabled then
Result.Port := updownPort.Position
else
@@ -836,6 +839,7 @@ procedure Tconnform.ListSessionsFocusChanged(Sender: TBaseVirtualTree;
editPassword.Text := Sess.Password;
chkLoginPrompt.Checked := Sess.LoginPrompt;
chkWindowsAuth.Checked := Sess.WindowsAuth;
chkCleartextPluginEnabled.Checked := Sess.CleartextPluginEnabled;
updownPort.Position := Sess.Port;
chkCompressed.Checked := Sess.Compressed;
updownQueryTimeout.Position := Sess.QueryTimeout;
@@ -1094,6 +1098,7 @@ procedure Tconnform.Modification(Sender: TObject);
or (Sess.Username <> editUsername.Text)
or (Sess.LoginPrompt <> chkLoginPrompt.Checked)
or (Sess.WindowsAuth <> chkWindowsAuth.Checked)
or (Sess.CleartextPluginEnabled <> chkCleartextPluginEnabled.Checked)
or (Sess.Port <> updownPort.Position)
or (Sess.Compressed <> chkCompressed.Checked)
or (Sess.QueryTimeout <> updownQueryTimeout.Position)
@@ -1122,7 +1127,8 @@ procedure Tconnform.Modification(Sender: TObject);
FOnlyPasswordModified := PasswordModified and (not FSessionModified);
FSessionModified := FSessionModified or PasswordModified;
if (Sender=editHost) or (Sender=editUsername) or (Sender=editPassword) or
(Sender=comboNetType) or (Sender=chkWindowsAuth) or (Sender=editPort) then begin
(Sender=comboNetType) or (Sender=chkWindowsAuth) or (Sender=editPort) or
(Sender=chkCleartextPluginEnabled) then begin
// Be sure to use the modified connection params next time the user clicks the "Databases" pulldown
FreeAndNil(FPopupDatabases);
end;
@@ -1170,6 +1176,7 @@ procedure Tconnform.ValidateControls;
else
lblHost.Caption := _('Hostname / IP:');
chkWindowsAuth.Enabled := Params.IsMSSQL;
chkCleartextPluginEnabled.Enabled := Params.IsMySQL;
lblUsername.Enabled := ((not chkLoginPrompt.Checked) or (not chkLoginPrompt.Enabled))
and ((not chkWindowsAuth.Checked) or (not chkWindowsAuth.Enabled));
editUsername.Enabled := lblUsername.Enabled;
@@ -217,7 +217,8 @@ TConnectionParameters = class(TObject)
FSessionPath, FSSLPrivateKey, FSSLCertificate, FSSLCACertificate, FSSLCipher, FServerVersion,
FSSHHost, FSSHUser, FSSHPassword, FSSHPlinkExe, FSSHPrivateKey: String;
FPort, FSSHPort, FSSHLocalPort, FSSHTimeout, FCounter, FQueryTimeout, FKeepAlive: Integer;
FLoginPrompt, FCompressed, FLocalTimeZone, FFullTableStatus, FWindowsAuth, FWantSSL, FIsFolder: Boolean;
FLoginPrompt, FCompressed, FLocalTimeZone, FFullTableStatus,
FWindowsAuth, FWantSSL, FIsFolder, FCleartextPluginEnabled: Boolean;
FSessionColor: TColor;
FLastConnect: TDateTime;
function GetImageIndex: Integer;
@@ -260,6 +261,7 @@ TConnectionParameters = class(TObject)
property Password: String read FPassword write FPassword;
property LoginPrompt: Boolean read FLoginPrompt write FLoginPrompt;
property WindowsAuth: Boolean read FWindowsAuth write FWindowsAuth;
property CleartextPluginEnabled: Boolean read FCleartextPluginEnabled write FCleartextPluginEnabled;
property AllDatabasesStr: String read FAllDatabases write FAllDatabases;
property Comment: String read FComment write FComment;
property StartupScriptFilename: String read FStartupScriptFilename write FStartupScriptFilename;
@@ -1127,6 +1129,7 @@ constructor TConnectionParameters.Create;
FHostname := AppSettings.GetDefaultString(asHost);
FLoginPrompt := AppSettings.GetDefaultBool(asLoginPrompt);
FWindowsAuth := AppSettings.GetDefaultBool(asWindowsAuth);
FCleartextPluginEnabled := AppSettings.GetDefaultBool(asCleartextPluginEnabled);
FUsername := DefaultUsername;
FPassword := AppSettings.GetDefaultString(asPassword);
FPort := DefaultPort;
@@ -1194,6 +1197,7 @@ constructor TConnectionParameters.Create(SessionRegPath: String);
FPassword := decrypt(AppSettings.ReadString(asPassword));
FLoginPrompt := AppSettings.ReadBool(asLoginPrompt);
FWindowsAuth := AppSettings.ReadBool(asWindowsAuth);
FCleartextPluginEnabled := AppSettings.ReadBool(asCleartextPluginEnabled);
FPort := MakeInt(AppSettings.ReadString(asPort));
FCompressed := AppSettings.ReadBool(asCompressed);
FAllDatabases := AppSettings.ReadString(asDatabases);
@@ -1249,6 +1253,7 @@ procedure TConnectionParameters.SaveToRegistry;
else begin
AppSettings.WriteString(asHost, FHostname);
AppSettings.WriteBool(asWindowsAuth, FWindowsAuth);
AppSettings.WriteBool(asCleartextPluginEnabled, FCleartextPluginEnabled);
AppSettings.WriteString(asUser, FUsername);
AppSettings.WriteString(asPassword, encrypt(FPassword));
AppSettings.WriteBool(asLoginPrompt, FLoginPrompt);
@@ -1825,6 +1830,10 @@ procedure TMySQLConnection.SetActive( Value: Boolean );
mysql_options(FHandle, Integer(MARIADB_OPT_TLS_VERSION), PAnsiChar('TLSv1,TLSv1.1,TLSv1.2,TLSv1.3'));
mysql_options(FHandle, Integer(MYSQL_OPT_TLS_VERSION), PAnsiChar('TLSv1,TLSv1.1,TLSv1.2,TLSv1.3'));

// Enable cleartext plugin
if Parameters.CleartextPluginEnabled then
mysql_options(FHandle, MYSQL_ENABLE_CLEARTEXT_PLUGIN, 1);

Connected := mysql_real_connect(
FHandle,
PAnsiChar(Utf8Encode(FinalHost)),
@@ -5046,24 +5055,24 @@ function TDBConnection.ExtractIdentifier(var SQL: String): String;
if rx.Exec(SQL) then begin
LeftQuote := rx.Match[0];
LeftPos := rx.MatchPos[0] + 1;

// Step forward for each character of the identifier
i := LeftPos;
RightPos := LeftPos;
while i < Length(SQL) do begin
if SQL[i] = LeftQuote then begin
if SQL[i+1] = SQL[i] then // take doubled/escaped quote char into account
Inc(i)
else begin
RightPos := i;
Break;
end;
end;
Result := Result + SQL[i];
Inc(i);
end;

if RightPos > LeftPos then

// Step forward for each character of the identifier
i := LeftPos;
RightPos := LeftPos;
while i < Length(SQL) do begin
if SQL[i] = LeftQuote then begin
if SQL[i+1] = SQL[i] then // take doubled/escaped quote char into account
Inc(i)
else begin
RightPos := i;
Break;
end;
end;
Result := Result + SQL[i];
Inc(i);
end;

if RightPos > LeftPos then
Delete(SQL, 1, RightPos+1);
end;
end;

0 comments on commit 0facfaa

Please sign in to comment.
You can’t perform that action at this time.