Skip to content

Commit

Permalink
Fix unexpected behavior of --lock when keepassxc is not running
Browse files Browse the repository at this point in the history
currently, when keepassxc is not running, the command `keepassxc --lock` opens a new keepass window and blocks until the window is closed.

Especially in locking scripts this is rather unexpected and  Ican't think of a case where someone explicitly starts keepass with --lock and wants this behaviour.

Rather --lock should always ensure, that there are no unlocked instances and exiting afterwards
  • Loading branch information
alangecker authored and droidmonkey committed Jan 29, 2023
1 parent 8846880 commit 5acc9b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7920,6 +7920,10 @@ Kernel: %3 %4</source>
This options is deprecated, use --set-key-file instead.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>KeePassXC is not running. No open database to lock</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>QtIOCompressor</name>
Expand Down
8 changes: 8 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ int main(int argc, char** argv)
return EXIT_SUCCESS;
}

if (parser.isSet(lockOption)) {
qWarning() << QObject::tr("KeePassXC is not running. No open database to lock").toUtf8().constData();

// still return with EXIT_SUCCESS because when used within a script for ensuring that there is no unlocked
// keepass database (e.g. screen locking) we can consider it as successful
return EXIT_SUCCESS;
}

if (!Crypto::init()) {
QString error = QObject::tr("Fatal error while testing the cryptographic functions.");
error.append("\n");
Expand Down

0 comments on commit 5acc9b6

Please sign in to comment.