Conversation
src/gui/Application.cpp
Outdated
| if (userName.isEmpty()) { | ||
| userName = qgetenv("USERNAME"); | ||
| } | ||
| QString identifier = "keepassx2"; |
There was a problem hiding this comment.
This should be changed to keepassxc
There was a problem hiding this comment.
Commit pushed.
|
I do not agree with this implementation as it adds the networking dependency to all builds. We explicitly moved networking out of the core build so that a totally unconnected app can be built. |
|
Can't we do that via DBus instead? |
|
Just an idea: it can be theoretically done via a mutex. Some of you may not like Microsoft, but nevertheless I've found that idea on their site (it's MFC most likely, but the idea can be borrowed) https://support.microsoft.com/en-us/help/243953/how-to-limit-32-bit-applications-to-one-instance-in-visual-c |
|
Thanks for the feedback! |
|
Better doing this with DBus or Mutex? @phoerious @droidmonkey |
|
Yes i think so. I do not want to reintroduce a network dependency for this feature. There are better ways to handle this. |
|
I just wanted to point out that I stumbled upon this PR because I was looking for a solution to limit KeePassXC to a single instance. I often accidentally open a second instance instead of opening the existing one. Since the linked issue (#99) is more about adding a key combination than about (the ability of) limiting to a single instance, I figured I'd drop this comment here. As a final note, thanks everyone for your work! 👍 |
|
Currently DBus is supported only on Linux Seems that the only cross-platform option are:
The implementation in this PR is already using a QLockFile but add a QLocalServer |
|
My 2 cents: There is also qtsingleapplication. We use it in qBittorrent and seems to work across all platforms. |
|
@sledgehammer999 thanks for the suggestion. From QLocalSocket documentation:
But still you will need to compile with Qt5::Network and like @droidmonkey said:
|
|
What do you define as as «totally unconnected app»? And what is the goal of getting that? You could call directly the low-level functions, thus avoiding the usage of Qt5::Network, but it would be doing the same in disguise. It may be worth if you just want to avoid linking with the library, though. It's not as if the lack of linking with Qt5::Network meant that the binary would be unable to perform network calls. |
|
Its more of a symbolic gesture to those individuals that want some greater assurance that their passwords are not potentially exposed to a network interface of any kind. It seems to me that a temporary lock file could easily do the trick. Just have to be clever about app crashes (store pid in the file and check for running?) |
|
QLockFile does that already. |
|
I was trying to develop a solution without using any Qt5::Network API. The main thing is: I've tried replacing the QLocalServer with unix signals and Win32 messages but that will make things more complicate. Sincerely, I think we should include QLocalServer and use this PR. I agree that a password manager shouldn't use the network stack at all. But like specified in the Qt docs:
This is not "making network connection", it will works even without a networkadapter |
|
Not linking the Qt5::Network API is indeed symbolic. I would simply accept that library and replace it with an optional module that -on modern Linux- sets up a seccomp sandbox forbidding any socket(2) call where domain is not AF_LOCAL. The main issue I see is that the seccomp filter is inherited through fork+execve. So, if the user opened an url, and that launched a new browser. That browser descendant of keepassxc would be unable to connect to the network (and probably fail bizarrely). |
|
I think this PR needs to be properly brought up to speed with the KeePassXC code base. We already integrate the Qt5::Network plugin with HTTP so it shouldn't be added to CMake. Also, this does not resolve #99 since that is asking for a global shortcut that raises and lowers the window similar to autotype shortcut. In fairness that issue was modified several times. |
|
@droidmonkey This is not meant to resolve #99 but rather #14 |
|
Yah I know, i edited the description to say that 😉 |
|
Missed the edit in the first post 😄 |
|
What type of works this PR needs? Can we use QLocalServer for detecting running instances? |
|
Let's do it, makes the most sense |
|
This PR already use it. It needs only a rebase and should be fine/ready to merge |
1f8f50f to
65edccb
Compare
65edccb to
58463bc
Compare
|
I rebased the PR, please check if it matches your expectations. |
|
So, this still requires QNetworking? |
|
@phoerious Yes, for QLocalSocket |
| mainWindow.raise(); | ||
| mainWindow.activateWindow(); | ||
| }); | ||
| QObject::connect(&app, SIGNAL(openFile(QString)), &mainWindow, SLOT(openDatabase(QString))); |
There was a problem hiding this comment.
Shouldn't all the stuff after this be skipped when another instance is already running?
There was a problem hiding this comment.
Actually there is a return 0 at line 61 (if another instance is already running).
(Maybe should that be return 1 instead?)
droidmonkey
left a comment
There was a problem hiding this comment.
Need to fix windows compile errors separately in ScreenLockListenerWin.cpp
- Added YubiKey 2FA integration for unlocking databases [#127] - Added TOTP support [#519] - Added CSV import tool [#146, #490] - Added KeePassXC CLI tool [#254] - Added diceware password generator [#373] - Added support for entry references [#370, #378] - Added support for Twofish encryption [#167] - Enabled DEP and ASLR for in-memory protection [#371] - Enabled single instance mode [#510] - Enabled portable mode [#645] - Enabled database lock on screensaver and session lock [#545] - Redesigned welcome screen with common features and recent databases [#292] - Multiple updates to search behavior [#168, #213, #374, #471, #603, #654] - Added auto-type fields {CLEARFIELD}, {SPACE}, {{}, {}} [#267, #427, #480] - Fixed auto-type errors on Linux [#550] - Prompt user prior to executing a cmd:// URL [#235] - Entry attributes can be protected (hidden) [#220] - Added extended ascii to password generator [#538] - Added new database icon to toolbar [#289] - Added context menu entry to empty recycle bin in databases [#520] - Added "apply" button to entry and group edit windows [#624] - Added macOS tray icon and enabled minimize on close [#583] - Fixed issues with unclean shutdowns [#170, #580] - Changed keyboard shortcut to create new database to CTRL+SHIFT+N [#515] - Compare window title to entry URLs [#556] - Implemented inline error messages [#162] - Ignore group expansion and other minor changes when making database "dirty" [#464] - Updated license and copyright information on souce files [#632] - Added contributors list to about dialog [#629]
Description
This PR merges an older KeepassX PR that implements a single-instance mode, meaning that an existing keepassxc instance is raised instead of starting a second one. This has been proposed here, but I did not find a corresponding pull request.
For flexibility, a command line switch should probably be added to disable the single-instance mode if desired.
Motivation and context
Single-instance mode allows raising keepassxc from the tray by running
keepassxcfrom a script or a global keyboard shortcut.Resolves #14.
How has this been tested?
Compiled with the following cmake flags:
-DWITH_TESTS=OFF -DWITH_XC_AUTOTYPE=ON -DWITH_XC_HTTP=ON -DWITH_ASAN=ONEverything seems to work fine. When running keepassxc repeatedly, it prints a message, notifies the running instance, and exits.
Types of changes
Checklist:
-DWITH_ASAN=ON. [REQUIRED]