#1827 Evaluate Environment Variables In KeePass.config.xml

KeePass_2.x
open
nobody
5
2014-02-27
2014-02-14
Source Forge 42
No

I use KeePass on multiple system and sync the databases via Dropbox. The challenge is that the path to the Dropbox folder is different on each system because I am logged using a different user name and the Dropbox folder is always in my user profile.

I also use a single KeePass.config.xml file that I place in the KeePass application folder so that KeePass works the same way on each system.

The problem is that the path to recently opened files stored in the KeePass.config.xml uses a relative path based on the location of the KeePass.exe file. This means that I can only use this feature on one system.

My feature request is that KeePass would evaluate and evaluate/replace environment variable in the path item so that the following entry <Path>%USERPROFILE%\Dropbox\KeePass\NewDatabase.kdbx</Path> would evaluates to C:\Users\John Doe\Dropbox\KeePass\NewDatabase.kdbx

As is stands now <Path>%USERPROFILE%\Dropbox\KeePass\NewDatabase.kdbx</Path> evaluates to C:\Program Files (x86)\KeePass Password Safe 2\%USERPROFILE%\Dropbox\KeePass\NewDatabase.kdbx

Discussion

  • wellread1
    wellread1
    2014-02-14

    I keep a separate command file in the KeePass application directory consisting of SETX commands to set up the necessary environment variables. This file needs only be run on initial setup or if I make a change (e.g. change the Dropbox folder location). It is easy to maintain and modify all the installation specific environment variable values that are defined in this file.

     
  • Paul
    Paul
    2014-02-14

    This can be done with a trigger.
    Add a Sync button to KeePass. Event: application started and ready, Action: Add custom toolbar button.
    Add a button pressed trigger. Event: custom toolbar button pressed. Action: Sync active database... In the File/URL box put the path of the database including environment variables.

    cheers, Paul

     
  • wellread1,
    Thanks I was not aware of SETX and it looks to be a useful utility. This does not however solve the use case I describe. The problem is that while KeePass will evaluate environment variables that are in the URL field in the database it does not evaluate them when reading in the KeePass.config.xml file.

    Paul,
    I must not have been clear in the user case. The problem I have is that I use the same KeePass database on multiple system and on each system the file under my profile (%USERPROFLE%) but the path is different. Coding triggers and buttons would mean that I would need to code a separate set for each system which does not scale well and means that on a new system it would not work until coded. If we could use environment variables a single configuration could be coded/configured to work on any system.

    I am sure there are also other use cases where evaluating environment variables from the KeePass.config.xml file would prove useful.

     
  • wellread1
    wellread1
    2014-02-14

    The paths stored in the KeePass.config.xml are a result of checking one of the "Remember options" (e.g. "Remember and automatically open used database on startup" or "Remember recently used files" or similar settings). They are maintained by KeePass and, presumably because they are not intended to be modified directly by the user, they don't support environment variables. However, there are ways to get around this limitation. Paul mentioned one, and I hinted at a further generalization that is possible.

    First a previously unmentioned method. Use a KeePass.config.enforced.xml to store your installation specific path settings (without using environment variables). These can contain the correctly specified paths, and will override the standard configuration. All settings in an enforced file are immune to modification by KeePass. Environment variables are neither needed or possible. The KeePass.config.enforced.xml need only contain the specific settings that you need to enforce.

    Paul's suggestion is an alternate solution to your problem. Triggers that act on the "Active database" (source databases) can scale well. Where needed (e.g. target databases), the fully qualified path can be stored in the trigger section of the keepass.config.xml file and will not be modified by KeePass. However, I agree that it is difficult to maintain a bunch of triggers containing hard coded paths. Fortunately environment variables can be used in paths in triggers, making it possible to generalize the paths. It is here that a command file containing the SETX commands required to set-up and maintain environment variables is useful.

     
    Last edit: wellread1 2014-02-14
  • wellread1,
    You are right I kept cutting and pasting KeePass.config.xml when in fact I did mean KeePass.config.enforced.xml, which is why all the settings are manually put in the file and don't change.

    I would like to point out that while most of the functionality beyond secure storage of information in KeePass is not "needed" it is non the less very useful and supporting environment variables in the configuration files may indeed be useful. I also reverse the right to be wrong if there is another way to get the same behavior that I have just not figured out.

    To that point thanks for the expanded explanation on triggers. I either missed or did not understand that environment variables could be used in triggers. I'll look into this and see if this will better meet our needs.

    One side note there is a piece of information I did not mention in my original use case as it did not seem relevant but in hind sight probably is important.

    We use the KeeAutoExec plugin in a small self contained database that is used to securely open a set of other databases. Therefore all we are trying to do is to programmatically designate the location of that first database in the configuration file such that it is either the only entry in the recent files list and/or is the "last database opened" (therefore automatically opened based on the KeePass setting) regardless of where it sits on the file system or if in fact it was actually the last database opened.

    While useful I want to try and avoid SETX so that KeePass does is not configured to rely on any third party tools to work as we intend.

     
    Last edit: Source Forge 42 2014-02-19
  • wellread1
    wellread1
    2014-02-19

    I use the KeeAutoExec plugin with a dedicated "autoopen.kdbx" that opens on KeePass application intializtion and whose path is specified with an enviornment variable. Both system and custom enviornment variables are supported. With this setup, a KeePass.config.enforced.xml would be entirely optional becasue the generalization is contained in the KeePass.config.xml file.

    SETX is a Microsoft command introduced in Windows Vista and Windows Server 2008. However it is not needed if system defined enviornment variables are sufficient.

    Posting in discussion first, and fully desribing your problem along with any thinking about potential solutions is preferable to posting a feature request first. It usually will result in a better defined request if one is still needed after discussion.

     
  • wellread1
    I'll start by agreeing with you that is it better to post in the forums first. I, with a great lack of humility, thought that I had a figured out an elegant solution to a problem that needed a new feature. After the input I recevied here along with revisting Triggers again (last time was pre 2.x) I now realize that my solution was 1. Not elegant and 2. Did not need any new features as it could all be done with Triggers from within the same configuration file.

    All,
    You can consider this feature request offically recinded. See you in the forums.