keepassxreboot / keepassxc

KeePassXC is a cross-platform community-driven port of the Windows application “Keepass Password Safe”.
https://keepassxc.org/
Other
20.04k stars 1.42k forks source link

keepassxc does not expand environment variables in URL Field #2406

Open priv opened 5 years ago

priv commented 5 years ago

Expected Behavior

System environment variables should be supported to align with original KeePass2. The name of the variable enclosed in '%' characters should be expanded. For example %TEMP% is replaced by the user's temporary path. ref: https://keepass.info/help/base/autourl.html

Current Behavior

unable to use environment variable in cmd://

Steps to Reproduce (for bugs)

  1. cmd://C:\Users\user\OneDrive\Application\pietty.exe works
  2. cmd://%USERPROFILE%\OneDrive\Application\pietty.exe does not work

Context

Switch from KeePass2 but behavior is not the same

Debug Info

KeePassXC - 2.3.4 Operating system: Windows 10 CPU architecture: x64

droidmonkey commented 5 years ago

We just pass the command off to the system to execute. It might be a mistake, but in your example you forgot to include the OneDrive folder after the %USERPROFILE%.

priv commented 5 years ago

Yes this is just an example, I copied by typing and made that mistake.

If I execute "%USERPROFILE%\OneDrive\Application\pietty.exe" from "Run" and it works too. I'll check keepassxc source and see if I can figure out why, thanks.

droidmonkey commented 5 years ago

I did some debugging and docs reading, looks like this is a Qt issue. There is no function that expands env vars prior to program execution. I wrote a proof of concept that worked and will weaponize it tomorrow in a PR. Good report, thank you!

phoerious commented 4 years ago

Has the PR been filed or is this just a very long night?

mharj commented 3 years ago

I think quite many of Keepass own "placehoders" (https://keepass.info/help/base/placeholders.html) are quite rarely used, but at least ENV variables and {ENV_DIRSEP} would be very nice on crossplatform usage when chain opening files. Relates kind of #477

heylix commented 2 years ago

I agree, this is also something that #3863 tried to introduce.

Currently, I'd really like to have my home folder as ENV variable so I can have the same database on my work laptop (LDAP credentials) and my private laptop/PC (my regular username). This would also be useful if I open stuff on my Android smartphone which has a completely different directory layout than proper Linux.

StayPirate commented 1 year ago

it would be nice to have expanded evnvar in "Backup destination" as well. I'd like to set that field in one of the following fortmat:

image

image

Would that be possible?

droidmonkey commented 1 year ago

The tilde should work

StayPirate commented 1 year ago

it doesn't for me, could that be related to the fact I use the flatpak installation? IMO it doesn't because if I use the absolute path /home/crazybyte/.config/keepassxc/{DB_FILENAME}.old.kdbx it works.

The following are the permission I set on flatpak:

[Context]
shared=network;ipc;
sockets=x11;wayland;ssh-auth;
devices=all;
filesystems=~/Nextcloud/Backups/Keepass;xdg-config/kdeglobals:ro;xdg-config/keepassxc;xdg-run/gvfs;

[Session Bus Policy]
org.freedesktop.secrets=own
org.freedesktop.Notifications=talk
com.canonical.Unity.Session=talk
org.kde.StatusNotifierWatcher=talk
org.kde.KGlobalSettings=talk
org.freedesktop.ScreenSaver=talk
com.canonical.AppMenu.Registrar=talk
org.gnome.SessionManager.Presence=talk
org.gnome.ScreenSaver=talk
org.kde.kconfig.notify=talk
org.gnome.SessionManager=talk

[System Bus Policy]
org.freedesktop.login1=talk

As you can see the flatpaked app has rw access to xdg-config/keepassxc, which is where I'm storing the backup db.

I the ~ really works for you?

droidmonkey commented 1 year ago

agreed it doesn't work. The error occurs here:

https://github.com/keepassxreboot/keepassxc/blob/64b3695e5136efef519105d46e128fee44aca683/src/gui/DatabaseWidget.cpp#L2087-L2089