fix: delete CLI-created session settings from registry after disconnect

Refs #2162
This commit is contained in:
Ansgar Becker
2025-12-09 19:09:44 +01:00
parent 24f3e36d58
commit 8778d404d7
2 changed files with 25 additions and 3 deletions

View File

@@ -2703,9 +2703,13 @@ begin
ConnectionParams.SSHTimeout := StrToIntDef(SshTimeout, ConnectionParams.SSHTimeout);
end;
// Ensure we have a session name to pass to InitConnection
if (ConnectionParams.SessionPath = '') and (ConnectionParams.Hostname <> '') then
ConnectionParams.SessionPath := ConnectionParams.Hostname;
if ConnectionParams.SessionPath.IsEmpty then begin
// Ensure we have a (random) session name to pass to InitConnection
ConnectionParams.SessionPath := IfEmpty(ConnectionParams.Hostname, 'temp')+'-'+GeneratePassword(4);
end;
// Delete stored session in Destroy:
ConnectionParams.DeleteAfterUse := True;
end;
// Check for valid filename(s) in parameters.

View File

@@ -310,6 +310,8 @@ type
TConnectionParameters = class(TObject)
strict private
FDeleteAfterUse: Boolean;
FLoadedFromSettings: Boolean;
FNetType: TNetType;
FHostname, FUsername, FPassword, FAllDatabases, FLibraryOrProvider, FComment, FStartupScriptFilename,
FSessionPath, FSSLPrivateKey, FSSLCertificate, FSSLCACertificate, FSSLCipher, FServerVersion,
@@ -330,7 +332,9 @@ type
public
constructor Create; overload;
constructor Create(SessionRegPath: String); overload;
destructor Destroy; override;
procedure SaveToRegistry;
property DeleteAfterUse: Boolean read FDeleteAfterUse write FDeleteAfterUse;
function CreateConnection(AOwner: TComponent): TDBConnection;
function CreateQuery(Connection: TDbConnection): TDBQuery;
function NetTypeName(LongFormat: Boolean): String;
@@ -1281,6 +1285,8 @@ constructor TConnectionParameters.Create;
begin
inherited Create;
FIsFolder := False;
FDeleteAfterUse := False;
FLoadedFromSettings := False;
FNetType := TNetType(AppSettings.GetDefaultInt(asNetType));
FHostname := DefaultHost;
@@ -1354,6 +1360,7 @@ begin
);
FNetType := ntMySQL_TCPIP;
end;
FLoadedFromSettings := True;
FHostname := AppSettings.ReadString(asHost);
FUsername := AppSettings.ReadString(asUser);
FPassword := decrypt(AppSettings.ReadString(asPassword));
@@ -1410,6 +1417,16 @@ begin
end;
end;
destructor TConnectionParameters.Destroy;
begin
if FDeleteAfterUse and (not FLoadedFromSettings) and (not FSessionPath.IsEmpty) then begin
if AppSettings.SessionPathExists(FSessionPath) then begin
AppSettings.SessionPath := FSessionPath;
AppSettings.DeleteCurrentKey;
end;
end;
end;
procedure TConnectionParameters.SaveToRegistry;
var
@@ -2130,6 +2147,7 @@ begin
FKeepAliveTimer.Free;
FFavorites.Free;
FInformationSchemaObjects.Free;
FParameters.Free;
inherited;
end;