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

Refs #2162
This commit is contained in:
Ansgar Becker
2025-12-05 15:39:55 +01:00
parent be0dd9b63c
commit d39cd0524c
2 changed files with 25 additions and 3 deletions

View File

@@ -2804,9 +2804,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

@@ -320,6 +320,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,
@@ -340,7 +342,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;
@@ -1420,6 +1424,8 @@ constructor TConnectionParameters.Create;
begin
inherited Create;
FIsFolder := False;
FDeleteAfterUse := False;
FLoadedFromSettings := False;
FNetType := TNetType(AppSettings.GetDefaultInt(asNetType));
FHostname := DefaultHost;
@@ -1493,6 +1499,7 @@ begin
);
FNetType := ntMySQL_TCPIP;
end;
FLoadedFromSettings := True;
FHostname := AppSettings.ReadString(asHost);
FUsername := AppSettings.ReadString(asUser);
FPassword := decrypt(AppSettings.ReadString(asPassword));
@@ -1549,6 +1556,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
@@ -2245,6 +2262,7 @@ begin
FKeepAliveTimer.Free;
FFavorites.Free;
FInformationSchemaObjects.Free;
FParameters.Free;
inherited;
end;