A way to relocate KeePass.config.xml (through Symbolic-Link?)
A lightweight and easy-to-use password manager
Brought to you by:
dreichl
To make updating KeePass portable versions easier I want to separate application files from user files (e.g. database, plugins dir, language, config). The database location is no problem, for the plugins directory I created a Symbolic-Link and for the language file I changed the path in KeePass.config.xml. So far all is good.
But when it comes to changing the location of the config file I'm out of options: it can't be supplied by commandline and a Symbolic-Link for KeePass.config.xml gets loaded on start, but gets deleted as soon as a config item is changed.
It would be great if KeePass writes the KeePass.config.xml to the location the Symbolic-Link points to.
Have you tried the -cfg-local: command line parameter?
http://keepass.info/help/base/cmdline.html
cheers, Paul
Hi Paul,
thanks for your response. I totally missed that parameter (shame), so I gave it a try. I started KeePass like this:
KeePass.exe -cfg-local:C:\Users\someuser\Documents\KeePass.config.xml and
KeePass.exe -cfg-local:..\KeePass.config.xml
Configuration is loaded fine, but:
I think there are two ways to solve this:
Let me know if I'm missing something.
Kind regards,
Thomas
Last edit: Thomas 2016-10-21
cheers, Paul
Ok, thanks for the suggestions. I started testing on a portable KeePass setup (which doesn't have a global config file yet).
Using -cfg-local combined with PreferUserConfiguration = true in my local config, KeePass will:
As soon as you start KeePass without -cfg-local, the global config is used. Which is by then a copy of the local user config, possibly containing private and/or plugin settings. To prevent this behaviour (and confusion about which config is loaded), I replaced the global config file by one containing only the PreferUserConfiguration = true setting. Changes in preferences will now be written to a third location: %AppData%\KeePass\ since no other local config location is provided.
After all this tinkering my issue still stands:
I cannot guarantee that KeePass is always started with the -cfg-local parameter. For example when opening KeePass from the file explorer by double-clicking .kdbx files or by starting Keepass from KeeFox in Firefox. It really seems more appropriate for KeePass to just follow basic file operations instead of a harsh delete/recreate:
Looking into the source code I think this could be a fix (hopefully not missing any implications):
// IOConnection.cs - public DeleteFile(), line 692:
Consider not calling this from FileTransactionEx.cs line 110, or dropping it altogether (don't know if deletefile is used elsewhere):
if(ioc.IsLocalFile()) { File.Delete(ioc.Path); return; }// IOConnection.cs - private OpenWriteLocal(), line 640:
Consider dropping:
return new FileStream(ioc.Path, FileMode.Create, FileAccess.Write, FileShare.None);In favor of:
return new FileStream(ioc.Path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);If you want to take a harder route that involves detecting if a file is a symolic link, you can use this to detect it:
Kind regards,
Thomas
Last edit: Thomas 2016-10-22
I've added support for this now. File transactions now are not used anymore for files that have a reparse point (e.g. symbolic links).
Here's the latest development snapshot for testing:
http://keepass.info/filepool/KeePass_161101c.zip
Thanks and best regards,
Dominik