Compare commits

...

252 Commits

Author SHA1 Message Date
Felix Geyer
a954e9a4d8 Update translations. 2015-09-06 23:41:29 +02:00
Felix Geyer
95c449481e Prepare beta 2 release. 2015-09-06 23:39:54 +02:00
Felix Geyer
0b43607aa1 Make sure we use the native file dialog on Windows and OS X. 2015-09-06 13:32:12 +02:00
Felix Geyer
e75efb8bfb Improve setting the default file extension in FileDialog.
Largely from PR #105 by Charles Brunet <charles@cbrunet.net>
2015-09-05 19:10:26 +02:00
Felix Geyer
d83fee89bd Fix building WITH_CXX11 on OS X. 2015-09-05 19:03:24 +02:00
Felix Geyer
98417d6465 Set default extension when selected filename doesn't have one.
Closes #79
2015-07-25 18:16:33 +02:00
Felix Geyer
0ea64afe92 Fix type of default value for options. 2015-07-25 18:13:57 +02:00
Felix Geyer
a862f62fe8 Set a default filename when saving a new database.
Closes #308
2015-07-25 17:47:45 +02:00
Felix Geyer
5bd525a6dd Use correct keycode when unregistering global shortcuts.
charToKeySym() is already correctly used in registerGlobalShortcut().
2015-07-22 20:38:03 +02:00
Felix Geyer
af3d896bdf Make setNativeLocks() non-fatal on OS X. 2015-07-21 23:12:20 +02:00
Felix Geyer
ceeb72a277 Pull QLockFile updates from the qtbase repository. 2015-07-21 23:11:02 +02:00
Felix Geyer
2c17fdcff0 Correct link order of testhashedblockstream.
Fixes FTBFS on Windows.
2015-07-21 23:08:12 +02:00
Florian Geyer
41a7c96968 Close search before locking database and add additional check on current group.
Closes #309.
2015-07-20 22:45:57 +02:00
Felix Geyer
98d9dae087 Test if reset() and close() write only one final block. 2015-07-20 21:51:32 +02:00
Felix Geyer
2033174d95 Test if we correctly detect errors when writing. 2015-07-20 21:35:48 +02:00
Felix Geyer
606e36acf3 Detect and display more errors when writing databases. 2015-07-20 21:35:48 +02:00
Felix Geyer
0422943d52 Explicitly close/reset streams so we can detect errors. 2015-07-20 21:35:48 +02:00
Felix Geyer
0024f2e30f Signal errors in QXmlStreamWriter upstream.
Unfortunately the method is only avaiable in Qt >= 4.8.
Not much we can do about that.
2015-07-20 21:35:43 +02:00
Felix Geyer
abe5e8ecea Don't write final block(s) if we already have. 2015-07-20 21:33:51 +02:00
Felix Geyer
61503a8047 SymmetricCipherStream: Add error handling when reading from the device. 2015-07-20 19:54:18 +02:00
Felix Geyer
fcb5deff0a SymmetricCipherStream: Fix error string when detecting an error while writing. 2015-07-20 19:53:17 +02:00
Felix Geyer
fdec16c3a0 Fix copyright file match for username-copy.png. 2015-07-19 21:16:22 +02:00
Felix Geyer
84ee8b993f Explicity hide the tray icon before deleting it.
In some conditions the tray icon stayed visible until the application
was closed.
Tested on Kubuntu 15.04 (KDE Plasma 5.2).
2015-07-19 21:14:08 +02:00
Felix Geyer
3d1c27ceb7 Copy the database in TestGui before opening it.
We don't want to create lock files in the source tree.
2015-07-19 19:33:47 +02:00
Felix Geyer
7d3fb58cf5 Fix lock file location in saveDatabaseAs().
Previously the directory of the lock file path was empty when
saving to a new file.
saveFile.open() doesn't create the file and canonicalPath()
only works when the file exists.
2015-07-19 00:41:35 +02:00
Felix Geyer
df5da2fcef Fix lock file handling in saveDatabaseAs(). 2015-07-18 22:46:45 +02:00
Felix Geyer
1226d1dbd5 Prepare next release. 2015-07-18 21:20:38 +02:00
Felix Geyer
607007f94f Display country in language list.
But only if the translation specifies one.
2015-07-18 18:38:41 +02:00
Felix Geyer
6327eaf587 Fix tab name for read-only databases. 2015-07-18 18:29:19 +02:00
Felix Geyer
b1fd99f4c4 Enable document mode of DatabaseTabWidget.
This fixes a visual artifact when the GTK style is used and
only one database tab is open.

Closes #131
2015-07-18 18:27:17 +02:00
Felix Geyer
d1331053c8 Document GetGitRevisionDescription.cmake license. 2015-07-18 17:37:48 +02:00
Felix Geyer
c6fe0da569 Abort closing the app if saving a database failed. 2015-07-18 17:36:08 +02:00
Florian Geyer
b9fe2c1bf9 Small clean up. 2015-07-18 13:23:36 +02:00
Florian Geyer
3efc8f457a Display git revision in about dialog. 2015-07-18 13:14:13 +02:00
Felix Geyer
65e8732eeb Remove --password command line option.
Passing passwords on the command line is unsafe.
2015-07-17 21:31:36 +02:00
Felix Geyer
e82015d419 Update translations. 2015-07-17 20:54:28 +02:00
Florian Geyer
fa0fe6d33d Make tab order consistent. 2015-07-16 23:50:35 +02:00
Felix Geyer
8be135adf9 Merge remote-tracking branch 'github/pr/54' 2015-07-16 23:12:52 +02:00
Jerome Leclanche
d04927ce7f Use a better GenericName 2015-07-16 23:07:21 +02:00
Felix Geyer
6889cc2f20 Another Qt 4.6 compatibility fix. 2015-07-16 22:55:50 +02:00
Felix Geyer
8325b20d36 Make QElapsedTimer optional in QLockFile.
This restores compatibility with Qt 4.6.
2015-07-16 21:52:08 +02:00
Felix Geyer
826cd472c8 Group all copy to clipboard menu entries together. 2015-07-16 20:09:23 +02:00
Felix Geyer
8ecab15c33 Merge remote-tracking branch 'github/pr/112'
Closes #149
2015-07-16 20:06:44 +02:00
Felix Geyer
c9520214e2 Merge remote-tracking branch 'github/pr/72' 2015-07-16 20:04:26 +02:00
Felix Geyer
6d1ca363af Remove support for clearing the Klipper history.
KDE Plasma 5 doesn't provide the DBus interface anymore and
this avoids the QtDBus dependency.
2015-07-16 20:02:10 +02:00
Felix Geyer
2170794d9c Guess the scheme when opening URLs.
Closes #293
2015-07-16 19:52:34 +02:00
Felix Geyer
719ac64851 Fix unused variable warning. 2015-07-16 19:49:41 +02:00
Felix Geyer
d3a7e0dee9 Merge remote-tracking branch 'github/pr/108' 2015-07-16 19:32:07 +02:00
Felix Geyer
240919335f Add missing EmptyUuids.xml test file. 2015-07-14 22:20:56 +02:00
Felix Geyer
ceb6a0383e Add ability to export databases to CSV files.
Based on implementation by Florian Geyer <blueice@fobos.de>

Closes #57
2015-07-14 22:14:34 +02:00
Felix Geyer
0185b112e1 Merge remote-tracking branch 'github/pr/92'
https://github.com/keepassx/keepassx/pull/92
2015-07-13 22:43:58 +02:00
Felix Geyer
af84261eb6 Avoid calling QDesktopServices::openUrl() when cmd is empty. 2015-07-13 22:41:03 +02:00
Felix Geyer
274f86fd04 Merge branch 'pr-94'
https://github.com/keepassx/keepassx/pull/94

Closes #244
2015-07-13 22:36:56 +02:00
Felix Geyer
bcc3108c3d Coding style cleanup. 2015-07-13 22:36:20 +02:00
Felix Geyer
5f1b286630 Merge branch 'pr-95'
https://github.com/keepassx/keepassx/pull/95

Closes #283
2015-07-13 22:22:45 +02:00
Felix Geyer
8ad48d6774 Protect against emitting inactivityDetected() while it'is still processed. 2015-07-13 21:25:48 +02:00
Felix Geyer
721bec9794 Make sure we don't lock the database while a dialog is open.
This can happen when
- the user is picking out a file to save the database as
- a dialog asking the user to save/discard/cancel the current database
  changes is active

It is dangerous to lock the databases while these actions are still
in progress.

Closes #208
2015-07-13 21:25:38 +02:00
Felix Geyer
c6105a08ab KeePass2XmlReader: Don't fail wheh nreading empty UUIDs.
Closes #298
2015-07-13 21:01:55 +02:00
Felix Geyer
154f1673e9 QSaveFile: Flush temporary file and fsync before renaming.
Closes #301
2015-07-13 21:01:53 +02:00
Felix Geyer
577609b3e3 Make calling QSaveFile::commit() non-fatal if it's not open. 2015-07-13 21:00:50 +02:00
Florian Geyer
f22069bb11 Use higher increment for transform rounds in benchmark.
Thanks to Sami Farin for providing a patch.

Closes #305.
2015-07-12 21:48:55 +02:00
Codifier
280a1aceb9 Bug #149
Moved the actionEntryCopyUsername and actionEntryCopyPassword actions to the root level of the context menu, for easier access and changed their labels to 'Copy username' and 'Copy password', respectively.
2015-07-12 20:54:02 +02:00
Andy Zeigler
bcd3de1180 Add keyboard shortcut (Ctrl-Alt-U) for copy URL to clipboard. 2015-06-12 19:29:02 -07:00
Florian Geyer
f4361dd4d5 Fix enabled state of copy notes action. 2015-06-05 18:37:22 +02:00
Felix Geyer
fc43aa1717 Update translations. 2015-05-15 00:20:23 +02:00
Felix Geyer
d553698b20 Travis CI: Pass --output-on-failure to ctest. 2015-05-14 20:46:59 +02:00
Felix Geyer
7db9c78855 Ignore libgcrypt errors in CryptoHash::CryptoHash().
Postponed until after 2.0 when I'll use excpetions.

Should be safe as we check basic functioning in Crypto::testSha256().
2015-05-14 20:44:17 +02:00
Felix Geyer
7a2c02f0df Initialize some instance variables in ctor.
Discovered by Coverity.

Most likely doesn't fix any actual bug but better be safe.
2015-05-14 16:58:53 +02:00
Felix Geyer
c535736853 Add GUI for changing default group auto-type sequence.
Closes #175
2015-05-14 12:59:36 +02:00
Felix Geyer
a8bf6a9782 Refactor Tools::disableCoreDumps().
- Use all available methods.
- Don't print a warning when no method is implmeneted on the platform.
2015-05-14 12:58:00 +02:00
Amir Pakdel
0458dad6dc Code cleanups 2015-05-13 14:34:48 -04:00
Felix Geyer
68373730bf Fix compiler warnings where keysyms are printed.
%lX expectes unsigned long which KeySym is an alias for.
2015-05-12 23:57:36 +02:00
Felix Geyer
5d9039ea89 Silence compiler warning about an unused variable. 2015-05-12 23:40:02 +02:00
Felix Geyer
7e1faadd11 Merge remote-tracking branch 'github/pr/96'
Closes #218
2015-05-12 23:35:19 +02:00
Felix Geyer
fceb93061d Merge remote-tracking branch 'github/pr/97'
Closes #290
2015-05-12 22:31:51 +02:00
Amir Pakdel
c9d007fcdf Always clearing ChangeMasterKeyWidget.m_key 2015-05-12 16:31:14 -04:00
Felix Geyer
eeb940c0dc Fix plugin path detection when installed with DESTDIR.
This is in no way perfect but should cover most common cases.

Closes #291
2015-05-12 22:24:59 +02:00
Felix Geyer
05b5446e94 Protect opened databases with a file lock.
Closes #18
2015-05-12 22:24:45 +02:00
Amir Pakdel
b45437d502 Refactored DatabaseWidget::currentEntryHas*() 2015-05-12 15:54:39 -04:00
Amir Pakdel
a599787a25 Bug #290
Show realted menu option to current entry only if the corresponding
field is not empty.
2015-05-12 15:50:10 -04:00
Amir Pakdel
58061af959 Bug #218
Do not accept faulty files as Key File. Moreover, do not clear keys
unless we have a key to add.
2015-05-12 15:17:39 -04:00
Amir Pakdel
8bf1bb0517 Bug #283
Updated messages related to saivng and closing a database to make
them more clear about what is going to happen.
2015-05-12 13:46:48 -04:00
Amir Pakdel
d26cff520f Bug #244
Supporting cmd:// URLs
2015-05-12 12:25:43 -04:00
dartraiden
04aa10cee7 Russian translation for .desktop file 2015-05-12 00:14:58 +03:00
Felix Geyer
ade684d501 Crypto::selfTest(): test AES in ECB mode. 2015-05-10 00:02:08 +02:00
Felix Geyer
4362c3ea38 Handle cipher errors in TransformKeyBenchmarkThread. 2015-05-09 23:38:04 +02:00
Felix Geyer
e0d4b4b625 Adapt Salsa20 backend to the new interface. 2015-05-09 23:21:50 +02:00
Felix Geyer
cfffdae573 Improve error reporing of layered streams. 2015-05-09 23:21:50 +02:00
Felix Geyer
f6243675c9 Warn if result of processInPlace() is unchecked.
Fix callers accordingly.
2015-05-09 23:21:50 +02:00
Felix Geyer
a762cef0a9 Catch and handle all errors from libgcrypt. 2015-05-09 23:21:44 +02:00
Felix Geyer
a7f4e2d0cd Add Twofish tests to Crypto::selfTest(). 2015-05-09 18:15:01 +02:00
Felix Geyer
ae013c2196 Don't run gcrypt self tests.
Seems to be broken on some distros that enable hmac verification
of the binary but ship the signature in a separate package.

We have our own test cases for the algorithms we care about.
2015-05-09 17:32:52 +02:00
Felix Geyer
eefe844dcd Merge remote-tracking branch 'github/pr/80'
https://github.com/keepassx/keepassx/pull/80
2015-05-06 20:56:57 +02:00
Felix Geyer
94111c3662 Merge remote-tracking branch 'github/pr/90'
https://github.com/keepassx/keepassx/pull/90
2015-05-06 20:53:56 +02:00
dartraiden
3fca61dc24 spelling correction, fixed typos 2015-05-06 19:38:43 +03:00
Felix Geyer
e41bf008e9 Use Q_BYTE_ORDER for endianness detection.
A hardcoded list of architectures is always incomplete.
2015-05-03 20:00:23 +02:00
Felix Geyer
6c9c0fd5c5 Look for a close button when pressing the escape key. 2015-05-03 19:59:11 +02:00
Felix Geyer
f3d956ceed Display a Close button for history items.
Previously we had Ok and Cancel with the same action.
2015-05-03 18:59:19 +02:00
Felix Geyer
b9c9c56059 Use common EditEntryWidget::clear() method. 2015-05-03 18:58:44 +02:00
Felix Geyer
bed58cde84 Fix crash when pressing "cancel" on a history item. 2015-05-03 18:48:58 +02:00
Felix Geyer
855d79e28f Document the libxtst dependency. 2015-05-01 19:34:57 +02:00
Felix Geyer
a044467d10 Install desktop file and icons to DATADIR instead of the hardcoded share/. 2015-04-14 23:23:14 +02:00
Felix Geyer
ecb2e337ef Hide Auto-Type action when it's not available. 2015-04-14 23:12:10 +02:00
Felix Geyer
2dde18b179 Adjust coding style. 2015-04-14 23:10:37 +02:00
Felix Geyer
6411b9bd66 Merge remote-tracking branch 'github/pr/82'
https://github.com/keepassx/keepassx/pull/82

Closes #145
2015-04-14 23:07:14 +02:00
Felix Geyer
cf0bc32b27 Store icons with a resolution of up to 128x128 px.
Follows what KeePass 2.29 will implement.
2015-04-08 18:22:13 +02:00
Felix Geyer
93ab7eb058 Use CMAKE_INSTALL_DATADIR to look for the data dir. 2015-04-08 18:07:53 +02:00
Felix Geyer
bd3ae05fcf Rename Extras menu to Tools and move Lock Databases action to it. 2015-04-05 10:48:08 +02:00
Felix Geyer
b055d524e8 Merge branch 'lockdb' 2015-04-05 10:38:58 +02:00
Felix Geyer
9e051e835b Close databases when they are locked.
Previously we've only hidden access to them.

Closes #275
2015-04-05 10:38:36 +02:00
Felix Geyer
3ab1072e9e Scale new custom icons down to 64x64 if they are larger. 2015-03-31 22:31:04 +02:00
Joe Harvell
00df73ced0 Issue #270 - turning off key location memory
Add general settting for whether or not to remember last key files
2015-03-14 22:06:53 -05:00
Felix Geyer
940a5026c1 Properly auto-type line breaks and tabs in text. 2015-03-13 22:24:29 +01:00
Felix Geyer
2631277184 Always sleep some time after the keymap has changed.
This works around a problem where sometimes chars are typed as if some
random modifiers are pressed.
2015-03-13 21:58:04 +01:00
Felix Geyer
b86b640860 Process events from the event loop before typing the first char. 2015-03-13 19:45:57 +01:00
Felix Geyer
2dfc740782 Rework handling of modifiers in auto-type.
Release all modifiers that are pressed and change the result.
2015-03-13 19:43:52 +01:00
Felix Geyer
e4985f4ff7 Get the xtest keyboard instead of the core keyboard.
If we don't find it fall back to the core keyboard.
2015-03-13 19:41:49 +01:00
Felix Geyer
22f579a59e Restore keyboard mapping only if we actually changed it. 2015-03-13 19:40:52 +01:00
Ben Boeckel
c9d12e93c2 cmake: remove the LOCATION query
Newer CMake deprecates the property. It isn't necessary anyways since
add_test will recognize targets as the executable name and make the full
path automatically.
2015-02-26 00:30:06 -05:00
Felix Geyer
778f01bcf1 Increase sleep time after remapping a keycode. 2015-02-24 22:00:44 +01:00
Felix Geyer
ccb7a4c96d Blacklist the KDE 5 root window. 2015-02-24 21:59:47 +01:00
Felix Geyer
33650c4a04 Add non-const version of Group::groupsRecursive(). 2015-01-11 16:20:24 +01:00
Victor Häggqvist
019cf9684c change tabindex, put password inputs after each other 2015-01-01 02:25:43 +01:00
Felix Geyer
835c411d12 Merge branch 'knu-fix_opening_attachment'
https://github.com/keepassx/keepassx/pull/71
2014-12-22 16:11:48 +01:00
Akinori MUSHA
e4758c1984 Fix the temporary filename template so that the original suffix is preserved. 2014-12-22 23:47:16 +09:00
Felix Geyer
eb22f0a2d8 Raise an error when parsing duplicate attributes/attachments. 2014-12-03 23:36:53 +01:00
Felix Geyer
3ea0592b53 Add hasKey() convenience methods. 2014-12-03 23:36:24 +01:00
Felix Geyer
876a75b572 Disable attachment buttons when none is selected. 2014-12-03 23:26:42 +01:00
Felix Geyer
c39898dad9 Support opening attachments directly. 2014-12-03 21:50:17 +01:00
Felix Geyer
07a3d7a696 Merge branch 'elrob-master'
https://github.com/keepassx/keepassx/pull/68
2014-12-02 08:34:30 +01:00
Rob Speller
7f412fbd7f Remove confusing grammar
Sentence still had 'either' because the sentence used to include twofish
2014-12-01 22:21:49 +00:00
Florian Geyer
2adc64939f Correct handling of keyfile argument.
Closes #223.
2014-12-01 22:47:22 +01:00
Felix Geyer
71d39865b3 Introduce a strict mode in KeePass2XmlReader.
Many errors are now ignored when not in strict mode so we can still parse
files that have been written by broken/incomplete implementations.
2014-12-01 21:52:51 +01:00
Felix Geyer
226c061c01 Remove Twofish reference from the README.
It isn't supported anymore.
2014-11-30 23:38:08 +01:00
Felix Geyer
dd2fbebb81 Add a translations section to the README. 2014-11-30 23:34:16 +01:00
Felix Geyer
889c742a33 Expand the build-dependency section of the README. 2014-11-30 23:31:25 +01:00
Felix Geyer
5cc3334325 Small README corrections. 2014-11-30 23:25:04 +01:00
Felix Geyer
e58be44523 Wrap overly long lines in README.md. 2014-11-30 23:23:29 +01:00
Felix Geyer
34a7321786 Merge branch 'hbetts-readme'
https://github.com/keepassx/keepassx/pull/46
2014-11-30 23:20:52 +01:00
Felix Geyer
07e4fbacd4 Remove ModifiedOnExpandedStateChanges config option.
I'm pretty sure noone knew what it actually does.
This is the sort of option users shouldn't be bothered with.
2014-11-30 23:04:17 +01:00
Felix Geyer
8fd69e084e Merge branch 'knu-untoggle_find'
https://github.com/keepassx/keepassx/pull/66
2014-11-30 22:54:23 +01:00
Akinori MUSHA
dd79105baa Complete remove the toggle search action. 2014-11-19 11:46:38 +09:00
Akinori MUSHA
b1c3814972 Make Ctrl+F not toggle the search mode but always enable it.
Switching back from other applications, the previous behavior of Ctrl+F
would often bother you in that it would dismiss the search widget if it
was already enabled when you meant by the key you wanted to perform a
search.

Making Ctrl+F always set you in search mode should save user from having
to care about the mode which is persistent across application switching
and database locking.
2014-11-18 19:46:53 +09:00
Felix Geyer
57107ea560 Enable debug mode for Travis CI builds. 2014-11-04 18:51:46 +01:00
Felix Geyer
4b3a82592c Define QT_NO_DEBUG for build type None.
Debian sets the the build type to None for package builds.
Make sure we don't enable asserts there.

Closes #237
2014-11-04 18:50:59 +01:00
Felix Geyer
6ecb8690f2 Update translations. 2014-11-02 15:42:39 +01:00
Felix Geyer
1c365b8417 Add Travis CI config. 2014-11-02 12:55:46 +01:00
Felix Geyer
315df0b8a8 Coding style fixes. 2014-11-02 11:46:51 +01:00
Felix Geyer
87468b648b Use specific monospace fonts as fallback on Mac OS X.
Qt (4.8.6) doesn't seem to be able to resolve the generic monospace
font family.

Closes #214
2014-11-02 11:44:03 +01:00
Felix Geyer
4cdb9a645d Add an option to display a tray icon.
Also implement "Minimize to tray" functionality.
2014-11-02 11:44:03 +01:00
Felix Geyer
870d7355ca Fix reading window title from _NET_WM_NAME.
XGetWindowProperty() returns 0 on success.

Closes #236
2014-11-02 11:44:03 +01:00
Florian Geyer
f1aa6aca26 Fix copy custom attributes menu. 2014-10-09 21:36:08 +02:00
Florian Geyer
72b59d541a Clear available languages when loading settings.
Thanks to Victor Häggqvist for spotting this.
2014-09-05 10:12:35 +02:00
Felix Geyer
0e8aa0bc6c Merge branch 'yayachiken-yayachiken-dev'
https://github.com/keepassx/keepassx/pull/58
2014-06-16 18:08:49 +02:00
David Kolossa
3a0648cf25 ! binds stronger than ==
This should just avoid useless copying if more than 1 attribute is
selected (and the option to copy attributes is unavailable).

This also fixes a clang warning.
2014-06-16 15:40:28 +02:00
David Kolossa
2e76385cae Fixed typo in INSTALL 2014-06-16 13:08:39 +02:00
Felix Geyer
867d14f7aa Merge branch 'movestill-fixConfigPath'
https://github.com/keepassx/keepassx/pull/49
2014-06-15 13:20:17 +02:00
Felix Geyer
0d6117bf4c Do some basic self-checks when initializing the crypto backend. 2014-06-15 11:17:40 +02:00
Felix Geyer
b417bf9187 Enable C++11 by default. 2014-06-13 21:33:36 +02:00
Felix Geyer
7137990a21 Clear clipboard only if copied text is still present.
Closes #198
2014-05-26 18:41:48 +02:00
Felix Geyer
916ab99d62 Skip TestQSaveFile::transactionalWriteErrorRenaming as user root.
You can't deny root access to a file.

Closes #201
2014-05-26 18:24:43 +02:00
Felix Geyer
5a31e055cf Show the window title when no entry matches for auto-type.
Closes #188
2014-05-18 12:09:46 +02:00
Felix Geyer
28694ae687 Add initial support for translations. 2014-05-18 01:33:22 +02:00
Felix Geyer
becd3a0019 Increase the EntryView default column size a bit. 2014-05-17 19:01:43 +02:00
Felix Geyer
8cc1e6008e Use plurals in translations. 2014-05-17 18:17:31 +02:00
Felix Geyer
910788c038 Mark some strings as untranslatable. 2014-05-17 18:17:31 +02:00
Felix Geyer
9391de74c7 Block non-user updates in DatabaseWidgetStateSync. 2014-05-17 18:17:31 +02:00
Florian Geyer
c806f9ebf4 Correct tr-calls. 2014-05-17 18:13:22 +02:00
Felix Geyer
e776de8eeb Remember and synchronize entry column sizes.
Closes #159
2014-05-17 12:51:16 +02:00
Felix Geyer
a25b28ffee Rename config option window/Geometry to GUI/MainWindowGeometry. 2014-05-17 11:38:48 +02:00
Felix Geyer
0e75e6ff03 Make DatabaseWidget splitter non-collapsible. 2014-05-17 11:27:04 +02:00
Felix Geyer
76da4a6cd4 Use QSplitter::setStretchFactor() convenience method. 2014-05-17 11:25:45 +02:00
Felix Geyer
8a4100adbd Make DatabaseWidget::emit{Group,Entry}ContextMenuRequested() private. 2014-05-17 11:22:45 +02:00
Felix Geyer
584f4b50bf Coding style fix. 2014-05-17 11:21:50 +02:00
Felix Geyer
9ac01c930d Drop DatabaseWidget::groupView() and entryView(). 2014-05-17 11:21:17 +02:00
Felix Geyer
d874f58a39 Synchronize DatabaseWidget splitter sizes. 2014-05-17 11:16:27 +02:00
Florian Geyer
05de45dadb Improve tab order. 2014-05-16 19:49:58 +02:00
Felix Geyer
4ab887c773 Initally select first entry in EntryView.
Closes #104
2014-05-16 19:10:30 +02:00
Florian Geyer
552ca7bf71 Stop search timer when closing search. 2014-05-16 18:56:01 +02:00
Felix Geyer
2d8ba2b394 Focus the search field instead of closing it when pressing the shortcut.
Closes #124
2014-05-16 13:10:26 +02:00
Felix Geyer
a6d44034a4 Put test executables into their default location. 2014-05-16 13:10:26 +02:00
Florian Geyer
77af79498c Move QTEST_GUILESS_MAIN statements before test cases. 2014-05-16 12:32:52 +02:00
Florian Geyer
ea3375490c Introduce interface for exporter. 2014-05-16 12:32:06 +02:00
Florian Geyer
204cd8d971 Move exporter to separate class. 2014-05-16 12:07:22 +02:00
Florian Geyer
c2940a8f18 Extend TestEntrySearcher. 2014-05-16 10:51:22 +02:00
Florian Geyer
4f60df029d Refactor TestEntrySearcher. 2014-05-16 00:26:09 +02:00
Florian Geyer
819cfd459a Move match method out of entry class. 2014-05-16 00:19:58 +02:00
Florian Geyer
c90ac914bb Refactor TestEntrySearcher. 2014-05-15 23:59:26 +02:00
Florian Geyer
8bf4826003 Move search into separate class. 2014-05-15 23:50:40 +02:00
Felix Geyer
e361b0dd81 Fix typo canDeleteCurrentGoup() -> canDeleteCurrentGroup(). 2014-05-15 22:56:36 +02:00
Felix Geyer
ce7e01a1b1 const-ify several methods. 2014-05-15 22:53:59 +02:00
Felix Geyer
cda5e990ac Show in-edit-mode warning when database is locked. 2014-05-15 22:51:13 +02:00
Florian Geyer
50cbd80925 Remove obsolete method in EntryView. 2014-05-15 18:55:17 +02:00
Felix Geyer
75d3e6261b Coding style fix. 2014-05-15 18:41:11 +02:00
Felix Geyer
bf39d0b1be Enable entry title matching but always ask before performing auto-type. 2014-05-15 18:34:12 +02:00
Felix Geyer
147cd4ed7b Add option to use the entry title for auto-type window matching. 2014-05-15 18:30:57 +02:00
Florian Geyer
9363d23e09 Remove dependency to Group- and EntryView from MainWindow. 2014-05-15 18:05:58 +02:00
Florian Geyer
b718e9d8f2 Make sure copy actions are disabled when database is locked.
Closes #189
2014-05-03 08:28:56 +02:00
Tim Gion
d6c30b0886 Fixed location of config file on Mac (and probably Windows). 2014-04-30 22:26:39 -04:00
Hutson Betts
7c7f0b93ae Add README.md file.
Add a dedicated README.md to the KeePassX repository to explain the
purpose of KeePassX, and to inform it's audience as to how they can
contribute.
2014-04-28 22:09:24 -05:00
Felix Geyer
e263c475c9 Increase default number of transform rounds to 100000.
Even low-end smartphone should be able to handle that.
2014-04-26 18:34:33 +02:00
Felix Geyer
c917096d3c Show the inherited value in EditGroupWidget. 2014-04-26 18:34:26 +02:00
Felix Geyer
5de62a5ef4 Add Group::resolveAutoTypeEnabled(). 2014-04-26 18:30:22 +02:00
Felix Geyer
7893a2e84d Rename Group::includeInSearch() to resolveSearchingEnabled().
Make it public and drop the resolveInherit parameter.
2014-04-26 18:27:52 +02:00
Florian Geyer
ad26d962dc Add option in settings for using group icons for newly created entries.
Closes #174
2014-04-14 23:38:09 +02:00
Florian Geyer
967a9f0195 Add check if parent group has custom icon.
Refs #174
2014-04-14 23:20:24 +02:00
Charles Brunet
6c663a19bf Use folder icon when not defaut icon 2014-04-14 22:59:38 +02:00
Felix Geyer
b194c29166 Show a dialog when no window matches for auto-type. 2014-04-14 22:57:25 +02:00
Felix Geyer
0b9167c78b Add an option to always ask before performing auto-type.
Closes #120
2014-04-14 22:57:18 +02:00
Felix Geyer
63ae460a80 Fix the alpha 6 release date. 2014-04-12 15:45:09 +02:00
Felix Geyer
43a1d54bba Prepare 2.0 alpha 6 release. 2014-04-12 15:29:20 +02:00
Felix Geyer
2963752585 Disallow global auto-typing when the database is locked. 2014-04-12 15:29:03 +02:00
Florian Geyer
1decdc6c11 Only save geometry when close event is accepted. 2014-03-24 20:03:40 +01:00
Florian Geyer
6659745e2b Rename settings key for window geometry. 2014-03-24 20:03:40 +01:00
Florian Geyer
1e2d1a1b17 Refactor saving of window geometry.
Closes #154
2014-03-24 20:03:40 +01:00
Florian Geyer
f300ca5b7b Remember window size.
Refs #154
2014-03-24 20:03:40 +01:00
Felix Geyer
b9370c6e79 More careful null checking and member initalization. 2014-03-22 12:10:49 +01:00
Florian Geyer
54bb7462f6 Add find action to entries menu.
Closes #122
2014-03-08 11:42:26 +01:00
Florian Geyer
4a08101a60 Remove obsolete ArgumentParser files. 2014-03-08 10:45:40 +01:00
Felix Geyer
809be5f89e Use the correct modifiers after remapping.
Sometimes the keysym is not mapped to the first column (no modifiers)
but to a diffferent column that needs modifiers.
Therefore we need re-read the table and search the whole row for the
correct keysym.
2014-01-19 23:32:00 +01:00
Felix Geyer
bf9a755bea Check all modifiers before declaring the remap keycode invalid.
Sometimes XChangeKeyboardMapping() maps the keysym to a modifier.
2014-01-19 21:40:25 +01:00
Felix Geyer
34b82da9aa Initialize cur_focus before it's used. 2014-01-19 20:09:19 +01:00
Felix Geyer
e0c59395da Merge branch 'AlbertWeichselbraun-bug-116-autotype-single-keycode' 2014-01-19 20:06:12 +01:00
Felix Geyer
b07de47e35 Add transform key benchmark to TestKeys. 2014-01-19 15:26:32 +01:00
Felix Geyer
586de64293 Restore compatibility with old Qt versions. 2014-01-19 10:46:53 +01:00
Felix Geyer
9321943e64 Install mime info package on Linux. 2014-01-18 23:43:44 +01:00
Felix Geyer
c00550078c Add KeePass 2 document icons. 2014-01-18 23:35:34 +01:00
Felix Geyer
2190260a68 Small optimization in SymmetricCipherGcrypt::processInPlace(). 2014-01-18 20:47:45 +01:00
Felix Geyer
678c4a8ece Set the application name and version in QApplication. 2014-01-18 15:31:24 +01:00
Felix Geyer
c2781274a0 Fix include guards of config-keepassx.h. 2014-01-18 15:30:58 +01:00
Felix Geyer
bc14898b13 Replace ArgumentParser with a backport of QCommandLineParser from Qt 5.2. 2014-01-18 15:23:55 +01:00
Felix Geyer
b6497d9245 Coding style fixes. 2014-01-14 21:00:27 +01:00
Felix Geyer
79d827ffa4 Add 22x22 icons for actions that are in the toolbar. 2014-01-14 19:55:38 +01:00
Felix Geyer
811eb2714f Add copy username and password actions to the clipboard.
Also add corresponding icons that I've put together from
various Oxygen icons.
2014-01-14 19:53:42 +01:00
Felix Geyer
a914b837a1 Drop new database action from the toolbar.
It's not a common operation.
2014-01-14 19:40:20 +01:00
Felix Geyer
04c9332a99 Drop superfluous PasswordGeneratorWidget::togglePassword slot. 2014-01-13 21:40:23 +01:00
Felix Geyer
97f374a189 Use monospace font in the password generator combo box. 2014-01-13 21:39:55 +01:00
Felix Geyer
6f3648d63e Uncheck the correct widget in ChangeMasterKeyWidget.
We want to enable the password group but mask the password in the line edit.
2014-01-13 00:24:29 +01:00
Felix Geyer
350cf4b00a Move password generator widget to the right row. 2014-01-13 00:24:29 +01:00
Felix Geyer
3af2307468 Reworked the PasswordGeneratorWidget.
It's loosely based on OS X PasswordAssistant. Generation happens as soon as a
change is made, and on open of the widget. A combobox has been added to allow
one to choose from some randomally-generated alternatives, and the UI is
generally been made a bit more compact.

Written by Michael Curtis <michael@moltenmercury.org> and revised by me.

Closes #119

https://github.com/keepassx/keepassx/pull/38
2014-01-13 00:24:25 +01:00
Felix Geyer
29c997e1bc Add an option to show passwords by default.
Closes #93
2014-01-12 17:23:47 +01:00
Felix Geyer
223c5a1651 Use an icon for the button that shows/masks passwords.
Closes #38

Additionally make use of the new PasswordEdit class where possible.
2014-01-12 17:13:10 +01:00
Felix Geyer
8b437821a2 Add ability to load icons with on/off state. 2014-01-12 17:13:10 +01:00
Felix Geyer
4ded95a060 Add PasswordEdit class.
It displays passwords in monospace which closes #51
2014-01-12 17:13:03 +01:00
Felix Geyer
0b6b149351 Use the libgcrypt SALSA20 cipher if available. 2014-01-12 13:42:56 +01:00
Felix Geyer
eee909e948 Parse the libgcrypt version in the cmake module. 2014-01-12 13:42:19 +01:00
Felix Geyer
8c7e655274 Add compatibility with libgcrypt 1.6.
Closes #129
2014-01-12 12:39:39 +01:00
Felix Geyer
8e86437e89 Disable settings spinboxes by default.
They get enabled when the corresponding checkboxes are checked.
2014-01-07 21:58:49 +01:00
Felix Geyer
a8edad1e27 Add option to lock databases after user inactivity.
Closes #62
2014-01-07 21:57:38 +01:00
Felix Geyer
41162ea2e8 Only try to click the focused button when pressing enter.
It makes no sense when pressing the escape button.
2014-01-02 10:51:51 +01:00
Albert Weichselbraun
0f91e0d141 Better naming & actually save m_currentRemapKeysym. 2013-12-16 09:41:43 +01:00
Albert Weichselbraun
6a50a76466 Track the last remapped keysym in m_currentRemapKeycode to enforce
a new computation of m_remapKeycode when the keyboard layout
changes.
(This fixes a potential problem with AddKeysym overwriting
 used keysyms after applying a new keyboard layout).
2013-12-16 09:28:16 +01:00
224 changed files with 27764 additions and 1479 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
src/version.h.cmake export-subst

19
.travis.yml Normal file
View File

@@ -0,0 +1,19 @@
os:
- linux
- osx
compiler:
- gcc
- clang
language: cpp
install:
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get -qq update; fi
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get -qq install cmake libqt4-dev libgcrypt11-dev zlib1g-dev libxtst-dev; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install cmake qt libgcrypt; fi
before_script: mkdir build && pushd build
script:
- cmake -DCMAKE_BUILD_TYPE=Debug -DWITH_GUI_TESTS=ON ..
- make
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then make test ARGS+="-E testgui --output-on-failure"; fi
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then xvfb-run -a --server-args="-screen 0 800x600x24" make test ARGS+="-R testgui --output-on-failure"; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then make test; fi

8
.tx/config Normal file
View File

@@ -0,0 +1,8 @@
[main]
host = https://www.transifex.com
[keepassx.keepassx_ents]
source_file = share/translations/keepassx_en.ts
file_filter = share/translations/keepassx_<lang>.ts
source_lang = en
type = QT

View File

@@ -1,3 +1,37 @@
2.0 Beta 2 (2015-09-06)
=========================
- Fix crash when locking with search UI open [#309]
- Fix file locking on Mac OS X [#327]
- Set default extension when saving a database [#79, #308]
2.0 Beta 1 (2015-07-18)
=========================
- Remember entry column sizes [#159]
- Add translations
- Support opening attachments directly
- Support cmd:// URLs [#244]
- Protect opened databases with a file lock [#18]
- Export to csv files [#57]
- Add optional tray icon [#153]
- Allow setting the default auto-type sequence for groups [#175]
- Make the kdbx parser more lenient
- Remove --password command line option [#285]
2.0 Alpha 6 (2014-04-12)
=========================
- Add option to lock databases after user inactivity [#62]
- Add compatibility with libgcrypt 1.6 [#129]
- Display passwords in monospace font [#51]
- Use an icon for the button that shows/masks passwords [#38]
- Add an option to show passwords by default [#93]
- Improve password generator design [#122]
- On Linux link .kdbx files with KeePassX
- Remember window size [#154]
- Disallow global auto-typing when the database is locked
2.0 Alpha 5 (2013-12-20)
=========================
@@ -42,7 +76,6 @@
- Sortable entry view
- Support building Mac OS X bundles
2.0 Alpha 1 (2012-05-07)
=========================

View File

@@ -32,10 +32,10 @@ include(CheckCXXSourceCompiles)
option(WITH_TESTS "Enable building of unit tests" ON)
option(WITH_GUI_TESTS "Enable building of GUI tests" OFF)
option(WITH_LTO "Enable Link Time Optimization (LTO)" OFF)
option(WITH_CXX11 "Build with the C++ 11 standard" OFF)
option(WITH_CXX11 "Build with the C++ 11 standard" ON)
set(KEEPASSX_VERSION "2.0 alpha 5")
set(KEEPASSX_VERSION_NUM "1.9.84")
set(KEEPASSX_VERSION "2.0 beta 2")
set(KEEPASSX_VERSION_NUM "1.9.92")
if("${CMAKE_C_COMPILER}" MATCHES "clang$" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_COMPILER_IS_CLANG 1)
@@ -118,6 +118,9 @@ endif()
if (WITH_CXX11)
add_gcc_compiler_cxxflags("-std=c++0x")
add_gcc_compiler_cflags("-ansi")
if(APPLE)
add_gcc_compiler_cxxflags("-stdlib=libc++")
endif()
else()
add_gcc_compiler_flags("-ansi")
endif()
@@ -151,7 +154,7 @@ else()
set(BIN_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}")
set(PLUGIN_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/keepassx")
set(DATA_INSTALL_DIR "${CMAKE_INSTALL_DATAROOTDIR}/keepassx")
set(DATA_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/keepassx")
endif()
if(WITH_TESTS)
@@ -159,14 +162,18 @@ if(WITH_TESTS)
endif(WITH_TESTS)
set(QT_REQUIRED_MODULES QtCore QtGui QtTest)
if(UNIX AND NOT APPLE)
set(QT_REQUIRED_MODULES ${QT_REQUIRED_MODULES} QtDBus)
endif()
find_package(Qt4 4.6.0 REQUIRED ${QT_REQUIRED_MODULES})
include(${QT_USE_FILE})
# Debian sets the the build type to None for package builds.
# Make sure we don't enable asserts there.
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_NONE QT_NO_DEBUG)
find_package(Gcrypt REQUIRED)
if(NOT (${GCRYPT_VERSION_STRING} VERSION_LESS "1.6.0"))
message(STATUS "Gcrypt ${GCRYPT_VERSION_STRING} supports the SALSA20 cipher")
set(GCRYPT_HAS_SALSA20 1)
endif()
find_package(ZLIB REQUIRED)

View File

@@ -25,6 +25,8 @@ Copyright: 2010-2012, Felix Geyer <debfx@fobos.de>
2012, Intel Corporation
2012, Nokia Corporation and/or its subsidiary(-ies)
2000-2008, Tom Sato <VEF00200@nifty.ne.jp>
2013, Laszlo Papp <lpapp@kde.org>
2013, David Faure <faure@kde.org>
License: GPL-2 or GPL-3
Files: cmake/GNUInstallDirs.cmake
@@ -134,7 +136,10 @@ Files: share/icons/application/*/actions/application-exit.png
share/icons/application/*/actions/document-save-as.png
share/icons/application/*/actions/edit-clear-locationbar-ltr.png
share/icons/application/*/actions/edit-clear-locationbar-rtl.png
share/icons/application/*/actions/password-copy.png
share/icons/application/*/actions/password-show-*.png
share/icons/application/*/actions/system-search.png
share/icons/application/*/actions/username-copy.png
share/icons/application/*/status/dialog-error.png
share/icons/application/*/status/dialog-information.png
share/icons/application/*/status/dialog-warning.png
@@ -178,3 +183,7 @@ Files: src/streams/qtiocompressor.*
tests/modeltest.*
Copyright: 2009-2012, Nokia Corporation and/or its subsidiary(-ies)
License: LGPL-2.1 or GPL-3
Files: cmake/GetGitRevisionDescription.cmake*
Copyright: 2009-2010, Iowa State University
License: Boost-1.0

View File

@@ -2,7 +2,7 @@ Building:
=========
mkdir build
cd build
cmake .. [CMAKE PARAMETERS]
cmake [CMAKE PARAMETERS] ..
make [-jX]
Common cmake parameters:

23
LICENSE.BOOST-1.0 Normal file
View File

@@ -0,0 +1,23 @@
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

129
README.md Normal file
View File

@@ -0,0 +1,129 @@
# KeePassX
## About
KeePassX is an application for people with extremely high demands on secure personal data management.
It has a light interface, is cross platform and published under the terms of the GNU General Public License.
KeePassX saves many different information e.g. user names, passwords, urls, attachments and comments in one single database.
For a better management user-defined titles and icons can be specified for each single entry.
Furthermore the entries are sorted in groups, which are customizable as well. The integrated search function allows to search in a single group or the complete database.
KeePassX offers a little utility for secure password generation. The password generator is very customizable, fast and easy to use.
Especially someone who generates passwords frequently will appreciate this feature.
The complete database is always encrypted with the AES (aka Rijndael) encryption algorithm using a 256 bit key.
Therefore the saved information can be considered as quite safe. KeePassX uses a database format that is compatible with [KeePass Password Safe](http://keepass.info/).
This makes the use of that application even more favorable.
## Install
KeePassX can be downloaded and installed using an assortment of installers available on the main [KeePassX website](http://www.keepassx.org).
KeePassX can also be installed from the official repositories of many Linux repositories.
If you wish to build KeePassX from source, rather than rely on the pre-compiled binaries, you may wish to read up on the _From Source_ section.
### Debian
To install KeePassX from the Debian repository:
```bash
sudo apt-get install keepassx
```
### Red Hat
Install KeePassX from the Red Hat (or CentOS) repository:
```bash
sudo yum install keepassx
```
### Windows / Mac OS X
Download the installer from the KeePassX [download](https://www.keepassx.org/downloads) page.
Once downloaded, double click on the file to execute the installer.
### From Source
#### Build Dependencies
The following tools must exist within your PATH:
* make
* cmake (>= 2.6.4)
* g++ or clang++
The following libraries are required:
* Qt 4 (>= 4.6)
* libgcrypt
* zlib
* libxtst (optional for auto-type on X11)
On Debian you can install them with:
```bash
sudo apt-get install build-essential cmake libqt4-dev libgcrypt11-dev zlib1g-dev
```
#### Build Steps
To compile from source:
```bash
mkdir build
cd build
cmake ..
make [-jX]
```
You will have the compiled KeePassX binary inside the `./build/src/` directory.
To install this binary execute the following:
```bash
sudo make install
```
More detailed instructions available in the INSTALL file.
## Contribute
Coordination of work between developers is handled through the [KeePassX development](https://www.keepassx.org/dev/) site.
Requests for enhancements, or reports of bugs encountered, can also be reported through the KeePassX development site.
However, members of the open-source community are encouraged to submit pull requests directly through GitHub.
### Clone Repository
Clone the repository to a suitable location where you can extend and build this project.
```bash
git clone https://github.com/keepassx/keepassx.git
```
**Note:** This will clone the entire contents of the repository at the HEAD revision.
To update the project from within the project's folder you can run the following command:
```bash
git pull
```
### Feature Requests
We're always looking for suggestions to improve our application. If you have a suggestion for improving an existing feature,
or would like to suggest a completely new feature for KeePassX, please file a ticket on the [KeePassX development](https://www.keepassx.org/dev/) site.
### Bug Reports
Our software isn't always perfect, but we strive to always improve our work. You may file bug reports on the [KeePassX development](https://www.keepassx.org/dev/) site.
### Pull Requests
Along with our desire to hear your feedback and suggestions, we're also interested in accepting direct assistance in the form of code.
Issue merge requests against our [GitHub repository](https://github.com/keepassx/keepassx).
### Translations
Translations are managed on [Transifex](https://www.transifex.com/projects/p/keepassx/) which offers a web interface.
Please join an existing language team or request a new one if there is none.

View File

@@ -17,7 +17,15 @@ find_path(GCRYPT_INCLUDE_DIR gcrypt.h)
find_library(GCRYPT_LIBRARIES gcrypt)
mark_as_advanced(GCRYPT_LIBRARIES GCRYPT_INCLUDE_DIR)
if(GCRYPT_INCLUDE_DIR AND EXISTS "${GCRYPT_INCLUDE_DIR}/gcrypt.h")
file(STRINGS "${GCRYPT_INCLUDE_DIR}/gcrypt.h" GCRYPT_H REGEX "^#define GCRYPT_VERSION \"[^\"]*\"$")
string(REGEX REPLACE "^.*GCRYPT_VERSION \"([0-9]+).*$" "\\1" GCRYPT_VERSION_MAJOR "${GCRYPT_H}")
string(REGEX REPLACE "^.*GCRYPT_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" GCRYPT_VERSION_MINOR "${GCRYPT_H}")
string(REGEX REPLACE "^.*GCRYPT_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" GCRYPT_VERSION_PATCH "${GCRYPT_H}")
set(GCRYPT_VERSION_STRING "${GCRYPT_VERSION_MAJOR}.${GCRYPT_VERSION_MINOR}.${GCRYPT_VERSION_PATCH}")
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Gcrypt DEFAULT_MSG GCRYPT_LIBRARIES GCRYPT_INCLUDE_DIR)
mark_as_advanced(GCRYPT_LIBRARIES GCRYPT_INCLUDE_DIR)

View File

@@ -0,0 +1,130 @@
# - Returns a version string from Git
#
# These functions force a re-configure on each git commit so that you can
# trust the values of the variables in your build system.
#
# get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])
#
# Returns the refspec and sha hash of the current head revision
#
# git_describe(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe on the source tree, and adjusting
# the output so that it tests false if an error occurs.
#
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe --exact-match on the source tree,
# and adjusting the output so that it tests false if there was no exact
# matching tag.
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.BOOST-1.0 or copy at
# http://www.boost.org/LICENSE_1_0.txt)
if(__get_git_revision_description)
return()
endif()
set(__get_git_revision_description YES)
# We must run the following at "include" time, not at function call time,
# to find the path to this module rather than the path to a calling list file
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
function(get_git_head_revision _refspecvar _hashvar)
set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
# We have reached the root directory, we are not in git
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
return()
endif()
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
endwhile()
# check if this is a submodule
if(NOT IS_DIRECTORY ${GIT_DIR})
file(READ ${GIT_DIR} submodule)
string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule})
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
endif()
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
if(NOT EXISTS "${GIT_DATA}")
file(MAKE_DIRECTORY "${GIT_DATA}")
endif()
if(NOT EXISTS "${GIT_DIR}/HEAD")
return()
endif()
set(HEAD_FILE "${GIT_DATA}/HEAD")
configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)
configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
"${GIT_DATA}/grabRef.cmake"
@ONLY)
include("${GIT_DATA}/grabRef.cmake")
set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
endfunction()
function(git_describe _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
get_git_head_revision(refspec hash)
if(NOT GIT_FOUND)
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return()
endif()
if(NOT hash)
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
return()
endif()
# TODO sanitize
#if((${ARGN}" MATCHES "&&") OR
# (ARGN MATCHES "||") OR
# (ARGN MATCHES "\\;"))
# message("Please report the following error to the project!")
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
#endif()
#message(STATUS "Arguments to execute_process: ${ARGN}")
execute_process(COMMAND
"${GIT_EXECUTABLE}"
describe
${hash}
${ARGN}
WORKING_DIRECTORY
"${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE
res
OUTPUT_VARIABLE
out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT res EQUAL 0)
set(out "${out}-${res}-NOTFOUND")
endif()
set(${_var} "${out}" PARENT_SCOPE)
endfunction()
function(git_get_exact_tag _var)
git_describe(out --exact-match ${ARGN})
set(${_var} "${out}" PARENT_SCOPE)
endfunction()

View File

@@ -0,0 +1,41 @@
#
# Internal file for GetGitRevisionDescription.cmake
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.BOOST-1.0 or copy at
# http://www.boost.org/LICENSE_1_0.txt)
set(HEAD_HASH)
file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
if(HEAD_CONTENTS MATCHES "ref")
# named branch
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
else()
configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
set(HEAD_HASH "${CMAKE_MATCH_1}")
endif()
endif()
else()
# detached HEAD
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
endif()
if(NOT HEAD_HASH)
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
string(STRIP "${HEAD_HASH}" HEAD_HASH)
endif()

View File

@@ -13,14 +13,19 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
add_subdirectory(translations)
file(GLOB DATABASE_ICONS icons/database/*.png)
install(FILES ${DATABASE_ICONS} DESTINATION ${DATA_INSTALL_DIR}/icons/database)
if(UNIX AND NOT APPLE)
install(DIRECTORY icons/application/ DESTINATION share/icons/hicolor
install(DIRECTORY icons/application/ DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor
FILES_MATCHING PATTERN "keepassx.png" PATTERN "keepassx.svgz")
install(FILES linux/keepassx.desktop DESTINATION share/applications)
install(DIRECTORY icons/application/ DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor
FILES_MATCHING PATTERN "application-x-keepassx.png" PATTERN "application-x-keepassx.svgz")
install(FILES linux/keepassx.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
install(FILES linux/keepassx.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/mime/packages)
endif(UNIX AND NOT APPLE)
if(APPLE)

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 670 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 783 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 838 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 711 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 798 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 966 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,9 +1,10 @@
[Desktop Entry]
Name=KeePassX
GenericName=Cross Platform Password Manager
GenericName=Password Manager
GenericName[de]=Passwortverwaltung
GenericName[es]=Gestor de contraseñas multiplataforma
GenericName[es]=Gestor de contraseñas
GenericName[fr]=Gestionnaire de mot de passe
GenericName[ru]=менеджер паролей
Exec=keepassx %f
Icon=keepassx
Terminal=false

8
share/linux/keepassx.xml Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="application/x-keepass2">
<comment>KeePass 2 database</comment>
<glob pattern="*.kdbx"/>
<icon name="application-x-keepassx"/>
</mime-type>
</mime-info>

View File

@@ -0,0 +1,26 @@
# Copyright (C) 2014 Felix Geyer <debfx@fobos.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 or (at your option)
# version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
file(GLOB TRANSLATION_FILES *.ts)
get_filename_component(TRANSLATION_EN_ABS keepassx_en.ts ABSOLUTE)
list(REMOVE_ITEM TRANSLATION_FILES keepassx_en.ts)
list(REMOVE_ITEM TRANSLATION_FILES ${TRANSLATION_EN_ABS})
message(STATUS ${TRANSLATION_FILES})
qt4_add_translation(QM_FILES ${TRANSLATION_FILES})
install(FILES ${QM_FILES} DESTINATION ${DATA_INSTALL_DIR}/translations)
add_custom_target(translations DEPENDS ${QM_FILES})
add_dependencies(${PROGNAME} translations)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="en_US">
<context>
<name>DatabaseWidget</name>
<message numerus="yes">
<source>Do you really want to move %n entry(s) to the recycle bin?</source>
<translation>
<numerusform>Do you really want to move %n entry to the recycle bin?</numerusform>
<numerusform>Do you really want to move %n entries to the recycle bin?</numerusform>
</translation>
</message>
</context>
<context>
<name>EditEntryWidget</name>
<message numerus="yes">
<source>%n week(s)</source>
<translation>
<numerusform>%n week</numerusform>
<numerusform>%n weeks</numerusform>
</translation>
</message>
<message numerus="yes">
<source>%n month(s)</source>
<translation>
<numerusform>%n month</numerusform>
<numerusform>%n months</numerusform>
</translation>
</message>
</context>
<context>
<name>EditWidgetIcons</name>
<message numerus="yes">
<source>Can&apos;t delete icon. Still used by %n item(s).</source>
<translation>
<numerusform>Can&apos;t delete icon. Still used by %n item.</numerusform>
<numerusform>Can&apos;t delete icon. Still used by %n items.</numerusform>
</translation>
</message>
</context>
</TS>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

12
share/translations/update.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/sh
BASEDIR=$(dirname $0)
cd $BASEDIR/../..
echo Updating source file
lupdate -no-ui-lines -disable-heuristic similartext -locations none -no-obsolete src -ts share/translations/keepassx_en.ts
lupdate -no-ui-lines -disable-heuristic similartext -locations none -pluralonly src -ts share/translations/keepassx_en_plurals.ts
echo Pulling translations from Transifex
tx pull -a --minimum-perc=80

View File

@@ -17,6 +17,17 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
configure_file(config-keepassx.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-keepassx.h)
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_HEAD)
git_describe(GIT_DESCRIBE --long)
if (NOT GIT_HEAD OR NOT GIT_DESCRIBE)
set(GIT_HEAD "")
set(GIT_DESCRIBE "")
endif()
configure_file(version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/version.h @ONLY)
set(keepassx_SOURCES
autotype/AutoType.cpp
autotype/AutoTypeAction.cpp
@@ -27,7 +38,6 @@ set(keepassx_SOURCES
autotype/WildcardMatcher.cpp
autotype/WindowSelectComboBox.cpp
autotype/test/AutoTypeTestInterface.h
core/ArgumentParser.cpp
core/AutoTypeAssociations.cpp
core/Config.cpp
core/Database.cpp
@@ -36,31 +46,33 @@ set(keepassx_SOURCES
core/Entry.cpp
core/EntryAttachments.cpp
core/EntryAttributes.cpp
core/EntrySearcher.cpp
core/FilePath.cpp
core/Global.h
core/Group.cpp
core/InactivityTimer.cpp
core/ListDeleter.h
core/Metadata.cpp
core/PasswordGenerator.cpp
core/qlockfile.cpp
core/qsavefile.cpp
core/qsavefile_p.h
core/SignalMultiplexer.cpp
core/TimeDelta.cpp
core/TimeInfo.cpp
core/ToDbExporter.cpp
core/Tools.cpp
core/Translator.cpp
core/Uuid.cpp
core/qcommandlineoption.cpp
core/qcommandlineparser.cpp
crypto/Crypto.cpp
crypto/CryptoHash.cpp
crypto/Random.cpp
crypto/salsa20/ecrypt-config.h
crypto/salsa20/ecrypt-machine.h
crypto/salsa20/ecrypt-portable.h
crypto/salsa20/ecrypt-sync.h
crypto/salsa20/salsa20.c
crypto/SymmetricCipher.cpp
crypto/SymmetricCipherBackend.h
crypto/SymmetricCipherGcrypt.cpp
crypto/SymmetricCipherSalsa20.cpp
format/CsvExporter.cpp
format/KeePass1.h
format/KeePass1Reader.cpp
format/KeePass2.h
@@ -77,6 +89,7 @@ set(keepassx_SOURCES
gui/DatabaseSettingsWidget.cpp
gui/DatabaseTabWidget.cpp
gui/DatabaseWidget.cpp
gui/DatabaseWidgetStateSync.cpp
gui/DialogyWidget.cpp
gui/DragTabBar.cpp
gui/EditWidget.cpp
@@ -88,7 +101,9 @@ set(keepassx_SOURCES
gui/LineEdit.cpp
gui/MainWindow.cpp
gui/MessageBox.cpp
gui/PasswordEdit.cpp
gui/PasswordGeneratorWidget.cpp
gui/PasswordComboBox.cpp
gui/SettingsWidget.cpp
gui/SortFilterHideProxyModel.cpp
gui/UnlockDatabaseWidget.cpp
@@ -116,6 +131,30 @@ set(keepassx_SOURCES
streams/SymmetricCipherStream.cpp
)
if(NOT GCRYPT_HAS_SALSA20)
set(keepassx_SOURCES
${keepassx_SOURCES}
crypto/salsa20/ecrypt-config.h
crypto/salsa20/ecrypt-machine.h
crypto/salsa20/ecrypt-portable.h
crypto/salsa20/ecrypt-sync.h
crypto/salsa20/salsa20.c
crypto/SymmetricCipherSalsa20.cpp
)
endif()
if(UNIX)
set(keepassx_SOURCES
${keepassx_SOURCES}
core/qlockfile_unix.cpp
)
elseif(MINGW)
set(keepassx_SOURCES
${keepassx_SOURCES}
core/qlockfile_win.cpp
)
endif()
set(keepassx_SOURCES_MAINEXE
main.cpp
)
@@ -133,6 +172,7 @@ set(keepassx_MOC
core/EntryAttachments.h
core/EntryAttributes.h
core/Group.h
core/InactivityTimer.h
core/Metadata.h
core/qsavefile.h
gui/AboutDialog.h
@@ -143,6 +183,7 @@ set(keepassx_MOC
gui/DatabaseSettingsWidget.h
gui/DatabaseTabWidget.h
gui/DatabaseWidget.h
gui/DatabaseWidgetStateSync.h
gui/DialogyWidget.h
gui/DragTabBar.h
gui/EditWidget.h
@@ -152,7 +193,9 @@ set(keepassx_MOC
gui/KeePass1OpenWidget.h
gui/LineEdit.h
gui/MainWindow.h
gui/PasswordEdit.h
gui/PasswordGeneratorWidget.h
gui/PasswordComboBox.h
gui/SettingsWidget.h
gui/SortFilterHideProxyModel.h
gui/UnlockDatabaseWidget.h
@@ -216,10 +259,6 @@ target_link_libraries(${PROGNAME}
${GCRYPT_LIBRARIES}
${ZLIB_LIBRARIES})
if(UNIX AND NOT APPLE)
target_link_libraries(${PROGNAME} ${QT_QTDBUS_LIBRARY})
endif()
set_target_properties(${PROGNAME} PROPERTIES ENABLE_EXPORTS ON)
if(APPLE)

View File

@@ -23,12 +23,14 @@
#include "autotype/AutoTypePlatformPlugin.h"
#include "autotype/AutoTypeSelectDialog.h"
#include "autotype/WildcardMatcher.h"
#include "core/Config.h"
#include "core/Database.h"
#include "core/Entry.h"
#include "core/FilePath.h"
#include "core/Group.h"
#include "core/ListDeleter.h"
#include "core/Tools.h"
#include "gui/MessageBox.h"
AutoType* AutoType::m_instance = Q_NULLPTR;
@@ -40,6 +42,7 @@ AutoType::AutoType(QObject* parent, bool test)
, m_pluginLoader(new QPluginLoader(this))
, m_plugin(Q_NULLPTR)
, m_executor(Q_NULLPTR)
, m_windowFromGlobal(0)
{
// prevent crash when the plugin has unresolved symbols
m_pluginLoader->setLoadHints(QLibrary::ResolveAllSymbolsHint);
@@ -145,6 +148,8 @@ void AutoType::performAutoType(const Entry* entry, QWidget* hideWindow, const QS
window = m_plugin->activeWindow();
}
QCoreApplication::processEvents(QEventLoop::AllEvents, 10);
Q_FOREACH (AutoTypeAction* action, actions) {
if (m_plugin->activeWindow() != window) {
qWarning("Active window changed, interrupting auto-type.");
@@ -187,8 +192,12 @@ void AutoType::performGlobalAutoType(const QList<Database*>& dbList)
if (entryList.isEmpty()) {
m_inAutoType = false;
QString message = tr("Couldn't find an entry that matches the window title:");
message.append("\n\n");
message.append(windowTitle);
MessageBox::information(Q_NULLPTR, tr("Auto-Type - KeePassX"), message);
}
else if (entryList.size() == 1) {
else if ((entryList.size() == 1) && !config()->get("security/autotypeask").toBool()) {
m_inAutoType = false;
performAutoType(entryList.first(), Q_NULLPTR, sequenceHash[entryList.first()]);
}
@@ -468,7 +477,15 @@ QList<AutoTypeAction*> AutoType::createActionFromTemplate(const QString& tmpl, c
QString resolved = entry->resolvePlaceholders(placeholder);
if (placeholder != resolved) {
Q_FOREACH (const QChar& ch, resolved) {
list.append(new AutoTypeChar(ch));
if (ch == '\n') {
list.append(new AutoTypeKey(Qt::Key_Enter));
}
else if (ch == '\t') {
list.append(new AutoTypeKey(Qt::Key_Tab));
}
else {
list.append(new AutoTypeChar(ch));
}
}
}
@@ -498,6 +515,12 @@ QString AutoType::autoTypeSequence(const Entry* entry, const QString& windowTitl
}
}
if (!match && config()->get("AutoTypeEntryTitleMatch").toBool() && !entry->title().isEmpty()
&& windowTitle.contains(entry->title(), Qt::CaseInsensitive)) {
sequence = entry->defaultAutoTypeSequence();
match = true;
}
if (!match) {
return QString();
}

View File

@@ -89,5 +89,7 @@ void AutoTypeExecutor::execDelay(AutoTypeDelay* action)
void AutoTypeExecutor::execClearField(AutoTypeClearField* action)
{
Q_UNUSED(action);
// TODO: implement
}

View File

@@ -39,6 +39,7 @@ AutoTypePlatformX11::AutoTypePlatformX11()
m_classBlacklist << "desktop_window" << "gnome-panel"; // Gnome
m_classBlacklist << "kdesktop" << "kicker"; // KDE 3
m_classBlacklist << "Plasma"; // KDE 4
m_classBlacklist << "plasmashell"; // KDE 5
m_classBlacklist << "xfdesktop" << "xfce4-panel"; // Xfce 4
m_currentGlobalKey = static_cast<Qt::Key>(0);
@@ -46,7 +47,8 @@ AutoTypePlatformX11::AutoTypePlatformX11()
m_keysymTable = Q_NULLPTR;
m_xkb = Q_NULLPTR;
m_specialCharacterKeycode = 0;
m_remapKeycode = 0;
m_currentRemapKeysym = NoSymbol;
m_modifierMask = ControlMask | ShiftMask | Mod1Mask | Mod4Mask;
m_loaded = true;
@@ -57,7 +59,9 @@ AutoTypePlatformX11::AutoTypePlatformX11()
void AutoTypePlatformX11::unload()
{
// Restore the KeyboardMapping to its original state.
AddKeysym(NoSymbol);
if (m_currentRemapKeysym != NoSymbol) {
AddKeysym(NoSymbol);
}
if (m_keysymTable) {
XFree(m_keysymTable);
@@ -156,7 +160,7 @@ uint AutoTypePlatformX11::qtToNativeModifiers(Qt::KeyboardModifiers modifiers)
void AutoTypePlatformX11::unregisterGlobalShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers)
{
KeyCode keycode = XKeysymToKeycode(m_dpy, keyToKeySym(key));
KeyCode keycode = XKeysymToKeycode(m_dpy, charToKeySym(key));
uint nativeModifiers = qtToNativeModifiers(modifiers);
XUngrabKey(m_dpy, keycode, nativeModifiers, m_rootWindow);
@@ -208,23 +212,26 @@ QString AutoTypePlatformX11::windowTitle(Window window, bool useBlacklist)
unsigned long after;
unsigned char* data = Q_NULLPTR;
// the window manager spec says we should read _NET_WM_NAME first, then fall back to WM_NAME
int retVal = XGetWindowProperty(m_dpy, window, m_atomNetWmName, 0, 1000, false, m_atomUtf8String,
&type, &format, &nitems, &after, &data);
if (retVal != 0 && data) {
if ((retVal == 0) && data) {
title = QString::fromUtf8(reinterpret_cast<char*>(data));
}
else {
XTextProperty textProp;
retVal = XGetTextProperty(m_dpy, window, &textProp, m_atomWmName);
if (retVal != 0 && textProp.value) {
if ((retVal != 0) && textProp.value) {
char** textList = Q_NULLPTR;
int count;
if (textProp.encoding == m_atomUtf8String) {
title = QString::fromUtf8(reinterpret_cast<char*>(textProp.value));
}
else if (XmbTextPropertyToTextList(m_dpy, &textProp, &textList, &count) == 0 && textList && count > 0) {
else if ((XmbTextPropertyToTextList(m_dpy, &textProp, &textList, &count) == 0)
&& textList && (count > 0)) {
title = QString::fromLocal8Bit(textList[0]);
}
else if (textProp.encoding == m_atomString) {
@@ -429,9 +436,21 @@ void AutoTypePlatformX11::updateKeymap()
int mod_index, mod_key;
XModifierKeymap *modifiers;
/* read keyboard map */
if (m_xkb != NULL) XkbFreeKeyboard(m_xkb, XkbAllComponentsMask, True);
m_xkb = XkbGetKeyboard (m_dpy, XkbCompatMapMask | XkbGeometryMask, XkbUseCoreKbd);
XDeviceInfo* devices;
int num_devices;
XID keyboard_id = XkbUseCoreKbd;
devices = XListInputDevices(m_dpy, &num_devices);
for (int i = 0; i < num_devices; i++) {
if (QString(devices[i].name) == "Virtual core XTEST keyboard") {
keyboard_id = devices[i].id;
break;
}
}
m_xkb = XkbGetKeyboard(m_dpy, XkbCompatMapMask | XkbGeometryMask, keyboard_id);
XDisplayKeycodes(m_dpy, &m_minKeycode, &m_maxKeycode);
if (m_keysymTable != NULL) XFree(m_keysymTable);
@@ -440,11 +459,13 @@ void AutoTypePlatformX11::updateKeymap()
&m_keysymPerKeycode);
/* determine the keycode to use for remapped keys */
if (m_specialCharacterKeycode == 0) {
inx = (m_remapKeycode - m_minKeycode) * m_keysymPerKeycode;
if (m_remapKeycode == 0 || !isRemapKeycodeValid()) {
for (keycode = m_minKeycode; keycode <= m_maxKeycode; keycode++) {
inx = (keycode - m_minKeycode) * m_keysymPerKeycode;
if (m_keysymTable[inx] == NoSymbol) {
m_specialCharacterKeycode = keycode;
m_remapKeycode = keycode;
m_currentRemapKeysym = NoSymbol;
break;
}
}
@@ -463,6 +484,26 @@ void AutoTypePlatformX11::updateKeymap()
}
}
XFreeModifiermap(modifiers);
/* Xlib needs some time until the mapping is distributed to
all clients */
// TODO: we should probably only sleep while in the middle of typing something
timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 30 * 1000 * 1000;
nanosleep(&ts, Q_NULLPTR);
}
bool AutoTypePlatformX11::isRemapKeycodeValid()
{
int baseKeycode = (m_remapKeycode - m_minKeycode) * m_keysymPerKeycode;
for (int i = 0; i < m_keysymPerKeycode; i++) {
if (m_keysymTable[baseKeycode + i] == m_currentRemapKeysym) {
return true;
}
}
return false;
}
void AutoTypePlatformX11::startCatchXErrors()
@@ -505,23 +546,19 @@ int AutoTypePlatformX11::x11ErrorHandler(Display* display, XErrorEvent* error)
*/
int AutoTypePlatformX11::AddKeysym(KeySym keysym)
{
if (m_specialCharacterKeycode == 0) {
if (m_remapKeycode == 0) {
return 0;
}
int inx = (m_specialCharacterKeycode - m_minKeycode) * m_keysymPerKeycode;
int inx = (m_remapKeycode- m_minKeycode) * m_keysymPerKeycode;
m_keysymTable[inx] = keysym;
XChangeKeyboardMapping(m_dpy, m_specialCharacterKeycode, m_keysymPerKeycode, &m_keysymTable[inx], 1);
m_currentRemapKeysym = keysym;
XChangeKeyboardMapping(m_dpy, m_remapKeycode, m_keysymPerKeycode, &m_keysymTable[inx], 1);
XFlush(m_dpy);
updateKeymap();
/* Xlib needs some time until the mapping is distributed to
all clients */
timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 10 * 1000 * 1000;
nanosleep(&ts, Q_NULLPTR);
return m_specialCharacterKeycode;
return m_remapKeycode;
}
/*
@@ -565,29 +602,42 @@ void AutoTypePlatformX11::SendModifier(XKeyEvent *event, unsigned int mask, int
* keysym.
*/
int AutoTypePlatformX11::GetKeycode(KeySym keysym, unsigned int *mask)
{
int keycode = XKeysymToKeycode(m_dpy, keysym);
if (keycode && keysymModifiers(keysym, keycode, mask)) {
return keycode;
}
/* no modifier matches => resort to remapping */
keycode = AddKeysym(keysym);
if (keycode && keysymModifiers(keysym, keycode, mask)) {
return keycode;
}
*mask = 0;
return 0;
}
bool AutoTypePlatformX11::keysymModifiers(KeySym keysym, int keycode, unsigned int *mask)
{
int shift, mod;
unsigned int mods_rtrn;
KeySym keysym_rtrn;
int keycode;
keycode = XKeysymToKeycode(m_dpy, keysym);
/* determine whether there is a combination of the modifiers
(Mod1-Mod5) with or without shift which returns keysym */
for (shift = 0; shift < 2; shift ++) {
for (mod = ControlMapIndex; mod <= Mod5MapIndex; mod ++) {
KeySym keysym_rtrn;
*mask = (mod == ControlMapIndex) ? shift : shift | (1 << mod);
XkbTranslateKeyCode(m_xkb, keycode, *mask, &mods_rtrn, &keysym_rtrn);
if (keysym_rtrn == keysym) {
return keycode;
return true;
}
}
}
/* no modifier matches => resort to remapping */
*mask = 0;
return AddKeysym(keysym);
return false;
}
@@ -605,10 +655,12 @@ void AutoTypePlatformX11::SendKeyPressedEvent(KeySym keysym)
int keycode;
if (keysym == NoSymbol) {
qWarning("No such key: keysym=0x%lX", static_cast<long>(keysym));
qWarning("No such key: keysym=0x%lX", keysym);
return;
}
XGetInputFocus(m_dpy, &cur_focus, &revert_to);
event.display = m_dpy;
event.window = cur_focus;
event.root = m_rootWindow;
@@ -622,24 +674,56 @@ void AutoTypePlatformX11::SendKeyPressedEvent(KeySym keysym)
Window root, child;
int root_x, root_y, x, y;
unsigned int mask;
unsigned int saved_mask;
unsigned int wanted_mask = 0;
unsigned int original_mask;
XQueryPointer(m_dpy, event.root, &root, &child, &root_x, &root_y, &x, &y, &mask);
saved_mask = mask;
XGetInputFocus(m_dpy, &cur_focus, &revert_to);
XQueryPointer(m_dpy, event.root, &root, &child, &root_x, &root_y, &x, &y, &original_mask);
/* determine keycode and mask for the given keysym */
keycode = GetKeycode(keysym, &mask);
keycode = GetKeycode(keysym, &wanted_mask);
if (keycode < 8 || keycode > 255) {
qWarning("Unable to get valid keycode for key: keysym=0x%lX", static_cast<long>(keysym));
qWarning("Unable to get valid keycode for key: keysym=0x%lX", keysym);
return;
}
/* release all modifiers */
SendModifier(&event, mask, KeyRelease);
event.state = original_mask;
SendModifier(&event, mask, KeyPress);
// modifiers that need to be pressed but aren't
unsigned int press_mask = wanted_mask & ~original_mask;
// modifiers that are pressed but maybe shouldn't
unsigned int release_check_mask = original_mask & ~wanted_mask;
// modifiers we need to release before sending the keycode
unsigned int release_mask = 0;
// check every release_check_mask individually if it affects the keysym we would generate
// if it doesn't we probably don't need to release it
for (int mod_index = ShiftMapIndex; mod_index <= Mod5MapIndex; mod_index ++) {
if (release_check_mask & (1 << mod_index)) {
unsigned int mods_rtrn;
KeySym keysym_rtrn;
XkbTranslateKeyCode(m_xkb, keycode, wanted_mask | (1 << mod_index), &mods_rtrn, &keysym_rtrn);
if (keysym_rtrn != keysym) {
release_mask |= (1 << mod_index);
}
}
}
// finally check if the combination of pressed modifiers that we chose to ignore affects the keysym
unsigned int mods_rtrn;
KeySym keysym_rtrn;
XkbTranslateKeyCode(m_xkb, keycode, wanted_mask | (release_check_mask & ~release_mask), &mods_rtrn, &keysym_rtrn);
if (keysym_rtrn != keysym) {
// oh well, release all the modifiers we don't want
release_mask = release_check_mask;
}
/* release all modifiers */
SendModifier(&event, release_mask, KeyRelease);
SendModifier(&event, press_mask, KeyPress);
/* press and release key */
event.keycode = keycode;
@@ -647,10 +731,10 @@ void AutoTypePlatformX11::SendKeyPressedEvent(KeySym keysym)
SendEvent(&event, KeyRelease);
/* release the modifiers */
SendModifier(&event, mask, KeyRelease);
SendModifier(&event, press_mask, KeyRelease);
/* restore the old keyboard mask */
SendModifier(&event, saved_mask, KeyPress);
SendModifier(&event, release_mask, KeyPress);
}
int AutoTypePlatformX11::MyErrorHandler(Display* my_dpy, XErrorEvent* event)

View File

@@ -72,11 +72,13 @@ private:
static int x11ErrorHandler(Display* display, XErrorEvent* error);
void updateKeymap();
bool isRemapKeycodeValid();
int AddKeysym(KeySym keysym);
void AddModifier(KeySym keysym);
void SendEvent(XKeyEvent* event, int event_type);
void SendModifier(XKeyEvent *event, unsigned int mask, int event_type);
int GetKeycode(KeySym keysym, unsigned int *mask);
bool keysymModifiers(KeySym keysym, int keycode, unsigned int *mask);
static int MyErrorHandler(Display* my_dpy, XErrorEvent* event);
@@ -106,8 +108,9 @@ private:
int m_minKeycode;
int m_maxKeycode;
int m_keysymPerKeycode;
/* dedicated 'special character' keycode */
int m_specialCharacterKeycode;
/* dedicated keycode for remapped keys */
unsigned int m_remapKeycode;
KeySym m_currentRemapKeysym;
KeyCode m_modifier_keycode[N_MOD_INDICES];
bool m_loaded;
};

View File

@@ -1,16 +1,21 @@
/* config-keepassx.h. Generated by cmake from config-keepassx.h.cmake */
#ifndef KEEPASSX_CONFIG_H
#define KEEPASSX_CONFIG_H
#ifndef KEEPASSX_CONFIG_KEEPASSX_H
#define KEEPASSX_CONFIG_KEEPASSX_H
#define KEEPASSX_VERSION "${KEEPASSX_VERSION}"
#define KEEPASSX_SOURCE_DIR "${CMAKE_SOURCE_DIR}"
#define KEEPASSX_BINARY_DIR "${CMAKE_BINARY_DIR}"
#define KEEPASSX_PREFIX_DIR "${CMAKE_INSTALL_PREFIX}"
#define KEEPASSX_PLUGIN_DIR "${PLUGIN_INSTALL_DIR}"
#define KEEPASSX_DATA_DIR "${DATA_INSTALL_DIR}"
#cmakedefine HAVE_PR_SET_DUMPABLE 1
#cmakedefine HAVE_RLIMIT_CORE 1
#cmakedefine HAVE_PT_DENY_ATTACH 1
#endif // KEEPASSX_CONFIG_H
#cmakedefine GCRYPT_HAS_SALSA20
#endif // KEEPASSX_CONFIG_KEEPASSX_H

View File

@@ -1,56 +0,0 @@
/*
* Copyright (C) 2013 Florian Geyer <blueice@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ArgumentParser.h"
const QStringList ArgumentParser::ArgumentKeys = QStringList() << "password" << "config" << "filename";
QHash<QString, QString> ArgumentParser::parseArguments(const QStringList& args)
{
QHash<QString, QString> argumentMap;
for (int i = 1; i < args.size(); i++) {
if (args[i].startsWith("--")) {
parseOption(i, argumentMap, args);
}
else if (!args[i].startsWith("-")) {
argumentMap.insert("filename", args[i]);
}
else {
qWarning("Unknown argument \"%s\"", qPrintable(args[i]));
}
}
return argumentMap;
}
void ArgumentParser::parseOption(int& i, QHash<QString, QString>& argumentMap, const QStringList& args)
{
if (args.size() < (i + 2)) {
qWarning("No value given for option \"%s\"", qPrintable(args[i]));
return;
}
QString argument(args[i].mid(2));
if (ArgumentKeys.contains(argument)) {
argumentMap.insert(argument, args[i + 1]);
}
else {
qWarning("Unknown option \"%s\" with value \"%s\"", qPrintable(args[i]), qPrintable(args[i+1]));
}
i++;
}

View File

@@ -71,7 +71,8 @@ Config::Config(QObject* parent)
userPath += "/keepassx/";
#else
userPath = QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
userPath += "/keepassx/";
// storageLocation() appends the application name ("/keepassx") to the end
userPath += "/";
#endif
userPath += "keepassx2.ini";
@@ -88,14 +89,23 @@ void Config::init(const QString& fileName)
m_settings.reset(new QSettings(fileName, QSettings::IniFormat));
m_defaults.insert("RememberLastDatabases", true);
m_defaults.insert("RememberLastKeyFiles", true);
m_defaults.insert("OpenPreviousDatabasesOnStartup", true);
m_defaults.insert("ModifiedOnExpandedStateChanges", true);
m_defaults.insert("AutoSaveAfterEveryChange", false);
m_defaults.insert("AutoSaveOnExit", false);
m_defaults.insert("ShowToolbar", true);
m_defaults.insert("MinimizeOnCopy", false);
m_defaults.insert("UseGroupIconOnEntryCreation", false);
m_defaults.insert("AutoTypeEntryTitleMatch", true);
m_defaults.insert("security/clearclipboard", true);
m_defaults.insert("security/clearclipboardtimeout", 10);
m_defaults.insert("security/lockdatabaseidle", false);
m_defaults.insert("security/lockdatabaseidlesec", 10);
m_defaults.insert("security/passwordscleartext", false);
m_defaults.insert("security/autotypeask", true);
m_defaults.insert("GUI/Language", "system");
m_defaults.insert("GUI/ShowTrayIcon", false);
m_defaults.insert("GUI/MinimizeToTray", false);
}
Config* Config::instance()
@@ -107,7 +117,7 @@ Config* Config::instance()
return m_instance;
}
void Config::createConfigFromFile(QString file)
void Config::createConfigFromFile(const QString& file)
{
Q_ASSERT(!m_instance);
m_instance = new Config(file, qApp);

View File

@@ -36,7 +36,7 @@ public:
void set(const QString& key, const QVariant& value);
static Config* instance();
static void createConfigFromFile(QString file);
static void createConfigFromFile(const QString& file);
static void createTempFileInstance();
private:

View File

@@ -37,7 +37,7 @@ Database::Database()
{
m_data.cipher = KeePass2::CIPHER_AES;
m_data.compressionAlgo = CompressionGZip;
m_data.transformRounds = 50000;
m_data.transformRounds = 100000;
m_data.hasKey = false;
setRootGroup(new Group());
@@ -188,32 +188,51 @@ void Database::setCompressionAlgo(Database::CompressionAlgorithm algo)
m_data.compressionAlgo = algo;
}
void Database::setTransformRounds(quint64 rounds)
bool Database::setTransformRounds(quint64 rounds)
{
if (m_data.transformRounds != rounds) {
quint64 oldRounds = m_data.transformRounds;
m_data.transformRounds = rounds;
if (m_data.hasKey) {
setKey(m_data.key);
if (!setKey(m_data.key)) {
m_data.transformRounds = oldRounds;
return false;
}
}
}
return true;
}
void Database::setKey(const CompositeKey& key, const QByteArray& transformSeed, bool updateChangedTime)
bool Database::setKey(const CompositeKey& key, const QByteArray& transformSeed,
bool updateChangedTime)
{
bool ok;
QString errorString;
QByteArray transformedMasterKey =
key.transform(transformSeed, transformRounds(), &ok, &errorString);
if (!ok) {
return false;
}
m_data.key = key;
m_data.transformSeed = transformSeed;
m_data.transformedMasterKey = key.transform(transformSeed, transformRounds());
m_data.transformedMasterKey = transformedMasterKey;
m_data.hasKey = true;
if (updateChangedTime) {
m_metadata->setMasterKeyChanged(Tools::currentDateTimeUtc());
}
Q_EMIT modifiedImmediate();
return true;
}
void Database::setKey(const CompositeKey& key)
bool Database::setKey(const CompositeKey& key)
{
setKey(key, randomGen()->randomArray(32));
return setKey(key, randomGen()->randomArray(32));
}
bool Database::hasKey() const

View File

@@ -69,7 +69,7 @@ public:
* Sets group as the root group and takes ownership of it.
* Warning: Be careful when calling this method as it doesn't
* emit any notifications so e.g. models aren't updated.
* The caller is responsible for cleaning up the pervious
* The caller is responsible for cleaning up the previous
root group.
*/
void setRootGroup(Group* group);
@@ -90,13 +90,14 @@ public:
void setCipher(const Uuid& cipher);
void setCompressionAlgo(Database::CompressionAlgorithm algo);
void setTransformRounds(quint64 rounds);
void setKey(const CompositeKey& key, const QByteArray& transformSeed, bool updateChangedTime = true);
bool setTransformRounds(quint64 rounds);
bool setKey(const CompositeKey& key, const QByteArray& transformSeed,
bool updateChangedTime = true);
/**
* Sets the database key and generates a random transform seed.
*/
void setKey(const CompositeKey& key);
bool setKey(const CompositeKey& key);
bool hasKey() const;
bool verifyKey(const CompositeKey& key) const;
void recycleEntry(Entry* entry);

View File

@@ -30,6 +30,7 @@ Entry::Entry()
, m_attachments(new EntryAttachments(this))
, m_autoTypeAssociations(new AutoTypeAssociations(this))
, m_tmpHistoryItem(Q_NULLPTR)
, m_modifiedSinceBegin(false)
, m_updateTimeinfo(true)
{
m_data.iconNumber = DefaultIconNumber;
@@ -578,25 +579,6 @@ const Database* Entry::database() const
}
}
bool Entry::match(const QString& searchTerm, Qt::CaseSensitivity caseSensitivity)
{
QStringList wordList = searchTerm.split(QRegExp("\\s"), QString::SkipEmptyParts);
Q_FOREACH (const QString& word, wordList) {
if (!wordMatch(word, caseSensitivity)) {
return false;
}
}
return true;
}
bool Entry::wordMatch(const QString& word, Qt::CaseSensitivity caseSensitivity)
{
return title().contains(word, caseSensitivity) ||
username().contains(word, caseSensitivity) ||
url().contains(word, caseSensitivity) ||
notes().contains(word, caseSensitivity);
}
QString Entry::resolvePlaceholders(const QString& str) const
{
QString result = str;

View File

@@ -141,7 +141,6 @@ public:
void setGroup(Group* group);
void setUpdateTimeinfo(bool value);
bool match(const QString& searchTerm, Qt::CaseSensitivity caseSensitivity);
Q_SIGNALS:
/**
@@ -157,7 +156,6 @@ private Q_SLOTS:
void updateModifiedSinceBegin();
private:
bool wordMatch(const QString& word, Qt::CaseSensitivity caseSensitivity);
const Database* database() const;
template <class T> bool set(T& property, const T& value);

View File

@@ -27,6 +27,11 @@ QList<QString> EntryAttachments::keys() const
return m_attachments.keys();
}
bool EntryAttachments::hasKey(const QString& key) const
{
return m_attachments.keys().contains(key);
}
QList<QByteArray> EntryAttachments::values() const
{
return m_attachments.values();

View File

@@ -30,6 +30,7 @@ class EntryAttachments : public QObject
public:
explicit EntryAttachments(QObject* parent = Q_NULLPTR);
QList<QString> keys() const;
bool hasKey(const QString& key) const;
QList<QByteArray> values() const;
QByteArray value(const QString& key) const;
void set(const QString& key, const QByteArray& value);

View File

@@ -36,6 +36,11 @@ QList<QString> EntryAttributes::keys() const
return m_attributes.keys();
}
bool EntryAttributes::hasKey(const QString& key) const
{
return m_attributes.keys().contains(key);
}
QList<QString> EntryAttributes::customKeys()
{
QList<QString> customKeys;

View File

@@ -32,6 +32,7 @@ class EntryAttributes : public QObject
public:
explicit EntryAttributes(QObject* parent = Q_NULLPTR);
QList<QString> keys() const;
bool hasKey(const QString& key) const;
QList<QString> customKeys();
QString value(const QString& key) const;
bool isProtected(const QString& key) const;

View File

@@ -0,0 +1,65 @@
/*
* Copyright (C) 2014 Florian Geyer <blueice@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "EntrySearcher.h"
#include "core/Group.h"
QList<Entry*> EntrySearcher::search(const QString &searchTerm, const Group* group, Qt::CaseSensitivity caseSensitivity)
{
if (!group->resolveSearchingEnabled()) {
return QList<Entry*>();
}
return searchEntries(searchTerm, group, caseSensitivity);
}
QList<Entry*> EntrySearcher::searchEntries(const QString& searchTerm, const Group* group, Qt::CaseSensitivity caseSensitivity)
{
QList<Entry*> searchResult;
Q_FOREACH (Entry* entry, group->entries()) {
searchResult.append(matchEntry(searchTerm, entry, caseSensitivity));
}
Q_FOREACH (Group* childGroup, group->children()) {
if (childGroup->searchingEnabled() != Group::Disable) {
searchResult.append(searchEntries(searchTerm, childGroup, caseSensitivity));
}
}
return searchResult;
}
QList<Entry*> EntrySearcher::matchEntry(const QString& searchTerm, Entry* entry, Qt::CaseSensitivity caseSensitivity)
{
QStringList wordList = searchTerm.split(QRegExp("\\s"), QString::SkipEmptyParts);
Q_FOREACH (const QString& word, wordList) {
if (!wordMatch(word, entry, caseSensitivity)) {
return QList<Entry*>();
}
}
return QList<Entry*>() << entry;
}
bool EntrySearcher::wordMatch(const QString& word, Entry* entry, Qt::CaseSensitivity caseSensitivity)
{
return entry->title().contains(word, caseSensitivity) ||
entry->username().contains(word, caseSensitivity) ||
entry->url().contains(word, caseSensitivity) ||
entry->notes().contains(word, caseSensitivity);
}

37
src/core/EntrySearcher.h Normal file
View File

@@ -0,0 +1,37 @@
/*
* Copyright (C) 2014 Florian Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KEEPASSX_ENTRYSEARCHER_H
#define KEEPASSX_ENTRYSEARCHER_H
#include <QString>
class Group;
class Entry;
class EntrySearcher
{
public:
QList<Entry*> search(const QString& searchTerm, const Group* group, Qt::CaseSensitivity caseSensitivity);
private:
QList<Entry*> searchEntries(const QString& searchTerm, const Group* group, Qt::CaseSensitivity caseSensitivity);
QList<Entry*> matchEntry(const QString& searchTerm, Entry* entry, Qt::CaseSensitivity caseSensitivity);
bool wordMatch(const QString &word, Entry *entry, Qt::CaseSensitivity caseSensitivity);
};
#endif // KEEPASSX_ENTRYSEARCHER_H

14
src/core/Exporter.h Normal file
View File

@@ -0,0 +1,14 @@
#ifndef KEEPASSX_EXPORTER_H
#define KEEPASSX_EXPORTER_H
class Database;
class Group;
class Exporter
{
public:
virtual Database* exportGroup(Group* group) = 0;
virtual ~Exporter() {}
};
#endif // KEEPASSX_EXPORTER_H

View File

@@ -49,13 +49,20 @@ QString FilePath::pluginPath(const QString& name)
pluginPaths << QCoreApplication::applicationDirPath();
QString systemPluginDir = KEEPASSX_PLUGIN_DIR;
if (systemPluginDir != ".") {
if (!QDir(systemPluginDir).isAbsolute()) {
systemPluginDir = QCoreApplication::applicationDirPath() + "/../" + systemPluginDir;
systemPluginDir = QDir(systemPluginDir).canonicalPath();
QString configuredPluginDir = KEEPASSX_PLUGIN_DIR;
if (configuredPluginDir != ".") {
if (QDir(configuredPluginDir).isAbsolute()) {
pluginPaths << configuredPluginDir;
}
else {
QString relativePluginDir = QString("%1/../%2")
.arg(QCoreApplication::applicationDirPath(), configuredPluginDir);
pluginPaths << QDir(relativePluginDir).canonicalPath();
QString absolutePluginDir = QString("%1/%2")
.arg(KEEPASSX_PREFIX_DIR, configuredPluginDir);
pluginPaths << QDir(absolutePluginDir).canonicalPath();
}
pluginPaths << systemPluginDir;
}
QStringList dirFilter;
@@ -117,8 +124,57 @@ QIcon FilePath::icon(const QString& category, const QString& name, bool fromThem
return icon;
}
QIcon FilePath::onOffIcon(const QString& category, const QString& name)
{
QString combinedName = category + "/" + name;
QString cacheName = "onoff/" + combinedName;
QIcon icon = m_iconCache.value(cacheName);
if (!icon.isNull()) {
return icon;
}
for (int i = 0; i < 2; i++) {
QIcon::State state;
QString stateName;
if (i == 0) {
state = QIcon::Off;
stateName = "off";
}
else {
state = QIcon::On;
stateName = "on";
}
QList<int> pngSizes;
pngSizes << 16 << 22 << 24 << 32 << 48 << 64 << 128;
QString filename;
Q_FOREACH (int size, pngSizes) {
filename = QString("%1/icons/application/%2x%2/%3-%4.png").arg(m_dataPath, QString::number(size),
combinedName, stateName);
if (QFile::exists(filename)) {
icon.addFile(filename, QSize(size, size), QIcon::Normal, state);
}
}
filename = QString("%1/icons/application/scalable/%3-%4.svgz").arg(m_dataPath, combinedName, stateName);
if (QFile::exists(filename)) {
icon.addFile(filename, QSize(), QIcon::Normal, state);
}
}
m_iconCache.insert(cacheName, icon);
return icon;
}
FilePath::FilePath()
{
const QString appDirPath = QCoreApplication::applicationDirPath();
bool isDataDirAbsolute = QDir::isAbsolutePath(KEEPASSX_DATA_DIR);
Q_UNUSED(isDataDirAbsolute);
if (false) {
}
#ifdef QT_DEBUG
@@ -126,15 +182,19 @@ FilePath::FilePath()
}
#endif
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
else if (testSetDir(QCoreApplication::applicationDirPath() + "/../share/keepassx")) {
else if (isDataDirAbsolute && testSetDir(KEEPASSX_DATA_DIR)) {
}
else if (!isDataDirAbsolute && testSetDir(QString("%1/../%2").arg(appDirPath, KEEPASSX_DATA_DIR))) {
}
else if (!isDataDirAbsolute && testSetDir(QString("%1/%2").arg(KEEPASSX_PREFIX_DIR, KEEPASSX_DATA_DIR))) {
}
#endif
#ifdef Q_OS_MAC
else if (testSetDir(QCoreApplication::applicationDirPath() + "/../Resources")) {
else if (testSetDir(appDirPath + "/../Resources")) {
}
#endif
#ifdef Q_OS_WIN
else if (testSetDir(QCoreApplication::applicationDirPath() + "/share")) {
else if (testSetDir(appDirPath + "/share")) {
}
#endif

View File

@@ -31,6 +31,7 @@ public:
QString pluginPath(const QString& name);
QIcon applicationIcon();
QIcon icon(const QString& category, const QString& name, bool fromTheme = true);
QIcon onOffIcon(const QString& category, const QString& name);
static FilePath* instance();

View File

@@ -248,9 +248,7 @@ void Group::setExpanded(bool expanded)
if (m_data.isExpanded != expanded) {
m_data.isExpanded = expanded;
updateTimeinfo();
if (config()->get("ModifiedOnExpandedStateChanges").toBool()) {
Q_EMIT modified();
}
Q_EMIT modified();
}
}
@@ -436,6 +434,20 @@ QList<const Group*> Group::groupsRecursive(bool includeSelf) const
groupList.append(this);
}
Q_FOREACH (const Group* group, m_children) {
groupList.append(group->groupsRecursive(true));
}
return groupList;
}
QList<Group*> Group::groupsRecursive(bool includeSelf)
{
QList<Group*> groupList;
if (includeSelf) {
groupList.append(this);
}
Q_FOREACH (Group* group, m_children) {
groupList.append(group->groupsRecursive(true));
}
@@ -500,22 +512,6 @@ void Group::copyDataFrom(const Group* other)
m_lastTopVisibleEntry = other->m_lastTopVisibleEntry;
}
Database* Group::exportToDb()
{
Q_ASSERT(database());
Database* db = new Database();
Group* clonedGroup = clone(Entry::CloneNewUuid | Entry::CloneIncludeHistory);
clonedGroup->setParent(db->rootGroup());
QSet<Uuid> customIcons = customIconsRecursive();
db->metadata()->copyCustomIcons(customIcons, database()->metadata());
db->copyAttributesFrom(database());
return db;
}
void Group::addEntry(Entry* entry)
{
Q_ASSERT(entry);
@@ -612,24 +608,7 @@ void Group::recCreateDelObjects()
}
}
QList<Entry*> Group::search(const QString& searchTerm, Qt::CaseSensitivity caseSensitivity,
bool resolveInherit)
{
QList<Entry*> searchResult;
if (includeInSearch(resolveInherit)) {
Q_FOREACH (Entry* entry, m_entries) {
if (entry->match(searchTerm, caseSensitivity)) {
searchResult.append(entry);
}
}
Q_FOREACH (Group* group, m_children) {
searchResult.append(group->search(searchTerm, caseSensitivity, false));
}
}
return searchResult;
}
bool Group::includeInSearch(bool resolveInherit)
bool Group::resolveSearchingEnabled() const
{
switch (m_data.searchingEnabled) {
case Inherit:
@@ -637,12 +616,27 @@ bool Group::includeInSearch(bool resolveInherit)
return true;
}
else {
if (resolveInherit) {
return m_parent->includeInSearch(true);
}
else {
return true;
}
return m_parent->resolveSearchingEnabled();
}
case Enable:
return true;
case Disable:
return false;
default:
Q_ASSERT(false);
return false;
}
}
bool Group::resolveAutoTypeEnabled() const
{
switch (m_data.autoTypeEnabled) {
case Inherit:
if (!m_parent) {
return true;
}
else {
return m_parent->resolveAutoTypeEnabled();
}
case Enable:
return true;

View File

@@ -65,6 +65,8 @@ public:
QString defaultAutoTypeSequence() const;
Group::TriState autoTypeEnabled() const;
Group::TriState searchingEnabled() const;
bool resolveSearchingEnabled() const;
bool resolveAutoTypeEnabled() const;
Entry* lastTopVisibleEntry() const;
bool isExpired() const;
@@ -99,6 +101,7 @@ public:
const QList<Entry*>& entries() const;
QList<Entry*> entriesRecursive(bool includeHistoryItems = false) const;
QList<const Group*> groupsRecursive(bool includeSelf) const;
QList<Group*> groupsRecursive(bool includeSelf);
QSet<Uuid> customIconsRecursive() const;
/**
* Creates a duplicate of this group including all child entries and groups.
@@ -109,10 +112,6 @@ public:
*/
Group* clone(Entry::CloneFlags entryFlags = Entry::CloneNewUuid | Entry::CloneResetTimeInfo) const;
void copyDataFrom(const Group* other);
Database* exportToDb();
QList<Entry*> search(const QString& searchTerm, Qt::CaseSensitivity caseSensitivity,
bool resolveInherit = true);
Q_SIGNALS:
void dataChanged(Group* group);
@@ -147,7 +146,6 @@ private:
void cleanupParent();
void recCreateDelObjects();
void updateTimeinfo();
bool includeInSearch(bool resolveInherit);
QPointer<Database> m_db;
Uuid m_uuid;

View File

@@ -0,0 +1,80 @@
/*
* Copyright (C) 2014 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "InactivityTimer.h"
#include <QCoreApplication>
#include <QTimer>
InactivityTimer::InactivityTimer(QObject* parent)
: QObject(parent)
, m_timer(new QTimer(this))
, m_active(false)
{
m_timer->setSingleShot(true);
connect(m_timer, SIGNAL(timeout()), SLOT(timeout()));
}
void InactivityTimer::setInactivityTimeout(int inactivityTimeout)
{
Q_ASSERT(inactivityTimeout > 0);
m_timer->setInterval(inactivityTimeout);
}
void InactivityTimer::activate()
{
if (!m_active) {
qApp->installEventFilter(this);
}
m_active = true;
m_timer->start();
}
void InactivityTimer::deactivate()
{
qApp->removeEventFilter(this);
m_active = false;
m_timer->stop();
}
bool InactivityTimer::eventFilter(QObject* watched, QEvent* event)
{
const QEvent::Type type = event->type();
if ( (type >= QEvent::MouseButtonPress && type <= QEvent::KeyRelease)
|| (type >= QEvent::HoverEnter && type <= QEvent::HoverMove)
|| (type == QEvent::Wheel) ) {
m_timer->start();
}
return QObject::eventFilter(watched, event);
}
void InactivityTimer::timeout()
{
// make sure we don't emit the signal a second time while it's still processed
if (!m_emitMutx.tryLock()) {
return;
}
if (m_active && !m_timer->isActive()) {
Q_EMIT inactivityDetected();
}
m_emitMutx.unlock();
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2014 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KEEPASSX_INACTIVITYTIMER_H
#define KEEPASSX_INACTIVITYTIMER_H
#include <QMutex>
#include <QObject>
#include "core/Global.h"
class QTimer;
class InactivityTimer : public QObject
{
Q_OBJECT
public:
explicit InactivityTimer(QObject* parent = Q_NULLPTR);
void setInactivityTimeout(int inactivityTimeout);
void activate();
void deactivate();
Q_SIGNALS:
void inactivityDetected();
protected:
bool eventFilter(QObject* watched, QEvent* event);
private Q_SLOTS:
void timeout();
private:
QTimer* m_timer;
bool m_active;
QMutex m_emitMutx;
};
#endif // KEEPASSX_INACTIVITYTIMER_H

View File

@@ -343,6 +343,22 @@ void Metadata::addCustomIcon(const Uuid& uuid, const QImage& icon)
Q_EMIT modified();
}
void Metadata::addCustomIconScaled(const Uuid& uuid, const QImage& icon)
{
QImage iconScaled;
// scale down to 128x128 if icon is larger
if (icon.width() > 128 || icon.height() > 128) {
iconScaled = icon.scaled(QSize(128, 128), Qt::KeepAspectRatio,
Qt::SmoothTransformation);
}
else {
iconScaled = icon;
}
addCustomIcon(uuid, iconScaled);
}
void Metadata::removeCustomIcon(const Uuid& uuid)
{
Q_ASSERT(!uuid.isNull());

View File

@@ -115,6 +115,7 @@ public:
void setProtectNotes(bool value);
// void setAutoEnableVisualHiding(bool value);
void addCustomIcon(const Uuid& uuid, const QImage& icon);
void addCustomIconScaled(const Uuid& uuid, const QImage& icon);
void removeCustomIcon(const Uuid& uuid);
void copyCustomIcons(const QSet<Uuid>& iconList, const Metadata* otherMetadata);
void setRecycleBinEnabled(bool value);

View File

@@ -19,15 +19,33 @@
#include "crypto/Random.h"
PasswordGenerator* PasswordGenerator::m_instance = Q_NULLPTR;
QString PasswordGenerator::generatePassword(int length,
const PasswordGenerator::CharClasses& classes,
const PasswordGenerator::GeneratorFlags& flags)
PasswordGenerator::PasswordGenerator()
: m_length(0)
, m_classes(0)
, m_flags(0)
{
Q_ASSERT(isValidCombination(length, classes, flags));
}
QVector<PasswordGroup> groups = passwordGroups(classes, flags);
void PasswordGenerator::setLength(int length)
{
m_length = length;
}
void PasswordGenerator::setCharClasses(const CharClasses& classes)
{
m_classes = classes;
}
void PasswordGenerator::setFlags(const GeneratorFlags& flags)
{
m_flags = flags;
}
QString PasswordGenerator::generatePassword() const
{
Q_ASSERT(isValid());
QVector<PasswordGroup> groups = passwordGroups();
QVector<QChar> passwordChars;
Q_FOREACH (const PasswordGroup& group, groups) {
@@ -38,14 +56,14 @@ QString PasswordGenerator::generatePassword(int length,
QString password;
if (flags & CharFromEveryGroup) {
if (m_flags & CharFromEveryGroup) {
for (int i = 0; i < groups.size(); i++) {
int pos = randomGen()->randomUInt(groups[i].size());
password.append(groups[i][pos]);
}
for (int i = groups.size(); i < length; i++) {
for (int i = groups.size(); i < m_length; i++) {
int pos = randomGen()->randomUInt(passwordChars.size());
password.append(passwordChars[pos]);
@@ -61,7 +79,7 @@ QString PasswordGenerator::generatePassword(int length,
}
}
else {
for (int i = 0; i < length; i++) {
for (int i = 0; i < m_length; i++) {
int pos = randomGen()->randomUInt(passwordChars.size());
password.append(passwordChars[pos]);
@@ -71,34 +89,31 @@ QString PasswordGenerator::generatePassword(int length,
return password;
}
bool PasswordGenerator::isValidCombination(int length,
const PasswordGenerator::CharClasses& classes,
const PasswordGenerator::GeneratorFlags& flags)
bool PasswordGenerator::isValid() const
{
if (classes == 0) {
if (m_classes == 0) {
return false;
}
else if (length == 0) {
else if (m_length == 0) {
return false;
}
if ((flags & CharFromEveryGroup) && (length < numCharClasses(classes))) {
if ((m_flags & CharFromEveryGroup) && (m_length < numCharClasses())) {
return false;
}
return true;
}
QVector<PasswordGroup> PasswordGenerator::passwordGroups(const PasswordGenerator::CharClasses& classes,
const PasswordGenerator::GeneratorFlags& flags)
QVector<PasswordGroup> PasswordGenerator::passwordGroups() const
{
QVector<PasswordGroup> passwordGroups;
if (classes & LowerLetters) {
if (m_classes & LowerLetters) {
PasswordGroup group;
for (int i = 97; i < (97 + 26); i++) {
if ((flags & ExcludeLookAlike) && (i == 108)) { // "l"
if ((m_flags & ExcludeLookAlike) && (i == 108)) { // "l"
continue;
}
@@ -107,11 +122,11 @@ QVector<PasswordGroup> PasswordGenerator::passwordGroups(const PasswordGenerator
passwordGroups.append(group);
}
if (classes & UpperLetters) {
if (m_classes & UpperLetters) {
PasswordGroup group;
for (int i = 65; i < (65 + 26); i++) {
if ((flags & ExcludeLookAlike) && (i == 73 || i == 79)) { // "I" and "O"
if ((m_flags & ExcludeLookAlike) && (i == 73 || i == 79)) { // "I" and "O"
continue;
}
@@ -120,11 +135,11 @@ QVector<PasswordGroup> PasswordGenerator::passwordGroups(const PasswordGenerator
passwordGroups.append(group);
}
if (classes & Numbers) {
if (m_classes & Numbers) {
PasswordGroup group;
for (int i = 48; i < (48 + 10); i++) {
if ((flags & ExcludeLookAlike) && (i == 48 || i == 49)) { // "0" and "1"
if ((m_flags & ExcludeLookAlike) && (i == 48 || i == 49)) { // "0" and "1"
continue;
}
@@ -133,7 +148,7 @@ QVector<PasswordGroup> PasswordGenerator::passwordGroups(const PasswordGenerator
passwordGroups.append(group);
}
if (classes & SpecialCharacters) {
if (m_classes & SpecialCharacters) {
PasswordGroup group;
for (int i = 33; i <= 47; i++) {
@@ -149,7 +164,7 @@ QVector<PasswordGroup> PasswordGenerator::passwordGroups(const PasswordGenerator
}
for (int i = 123; i <= 126; i++) {
if ((flags & ExcludeLookAlike) && (i == 124)) { // "|"
if ((m_flags & ExcludeLookAlike) && (i == 124)) { // "|"
continue;
}
@@ -162,35 +177,22 @@ QVector<PasswordGroup> PasswordGenerator::passwordGroups(const PasswordGenerator
return passwordGroups;
}
int PasswordGenerator::numCharClasses(const PasswordGenerator::CharClasses& classes)
int PasswordGenerator::numCharClasses() const
{
int numClasses = 0;
if (classes & LowerLetters) {
if (m_classes & LowerLetters) {
numClasses++;
}
if (classes & UpperLetters) {
if (m_classes & UpperLetters) {
numClasses++;
}
if (classes & Numbers) {
if (m_classes & Numbers) {
numClasses++;
}
if (classes & SpecialCharacters) {
if (m_classes & SpecialCharacters) {
numClasses++;
}
return numClasses;
}
PasswordGenerator* PasswordGenerator::instance()
{
if (!m_instance) {
m_instance = new PasswordGenerator();
}
return m_instance;
}
PasswordGenerator::PasswordGenerator()
{
}

View File

@@ -45,29 +45,28 @@ public:
};
Q_DECLARE_FLAGS(GeneratorFlags, GeneratorFlag)
QString generatePassword(int length, const PasswordGenerator::CharClasses& classes,
const PasswordGenerator::GeneratorFlags& flags);
bool isValidCombination(int length, const PasswordGenerator::CharClasses& classes,
const PasswordGenerator::GeneratorFlags& flags);
static PasswordGenerator* instance();
private:
public:
PasswordGenerator();
QVector<PasswordGroup> passwordGroups(const PasswordGenerator::CharClasses& classes,
const PasswordGenerator::GeneratorFlags& flags);
int numCharClasses(const PasswordGenerator::CharClasses& classes);
void setLength(int length);
void setCharClasses(const CharClasses& classes);
void setFlags(const GeneratorFlags& flags);
static PasswordGenerator* m_instance;
bool isValid() const;
QString generatePassword() const;
private:
QVector<PasswordGroup> passwordGroups() const;
int numCharClasses() const;
int m_length;
CharClasses m_classes;
GeneratorFlags m_flags;
Q_DISABLE_COPY(PasswordGenerator)
};
inline PasswordGenerator* passwordGenerator() {
return PasswordGenerator::instance();
}
Q_DECLARE_OPERATORS_FOR_FLAGS(PasswordGenerator::CharClasses)
Q_DECLARE_OPERATORS_FOR_FLAGS(PasswordGenerator::GeneratorFlags)

39
src/core/ToDbExporter.cpp Normal file
View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2014 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2014 Florian Geyer <blueice@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ToDbExporter.h"
#include "core/Database.h"
#include "core/Group.h"
#include "core/Metadata.h"
Database* ToDbExporter::exportGroup(Group* group)
{
Database* oldDb = group->database();
Q_ASSERT(oldDb);
Database* db = new Database();
Group* clonedGroup = group->clone(Entry::CloneNewUuid | Entry::CloneIncludeHistory);
clonedGroup->setParent(db->rootGroup());
QSet<Uuid> customIcons = group->customIconsRecursive();
db->metadata()->copyCustomIcons(customIcons, oldDb->metadata());
db->copyAttributesFrom(oldDb);
return db;
}

View File

@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013 Florian Geyer <blueice@fobos.de>
* Copyright (C) 2014 Felix Geyer <debfx@fobos.de>
* Copyright (C) 2014 Florian Geyer <blueice@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -15,23 +16,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KEEPASSX_ARGUMENTPARSER_H
#define KEEPASSX_ARGUMENTPARSER_H
#ifndef KEEPASSX_TODBEXPORTER_H
#define KEEPASSX_TODBEXPORTER_H
#include "core/Global.h"
#include "core/Exporter.h"
#include <QHash>
#include <QStringList>
class Database;
class Group;
class ArgumentParser
class ToDbExporter : Exporter
{
public:
static QHash<QString, QString> parseArguments(const QStringList& args);
private:
static void parseOption(int& i, QHash<QString, QString>& argumentMap, const QStringList& args);
static const QStringList ArgumentKeys;
Database* exportGroup(Group* group);
};
#endif // KEEPASSX_ARGUMENTPARSER_H
#endif // KEEPASSX_TODBEXPORTER_H

View File

@@ -39,10 +39,12 @@
#include "config-keepassx.h"
#if defined(HAVE_RLIMIT_CORE)
#include <sys/resource.h>
#endif
#if defined(HAVE_PR_SET_DUMPABLE)
#include <sys/prctl.h>
#elif defined(HAVE_RLIMIT_CORE)
#include <sys/resource.h>
#endif
#ifdef HAVE_PT_DENY_ATTACH
@@ -222,21 +224,23 @@ QString platform()
void disableCoreDumps()
{
bool success = false;
// default to true
// there is no point in printing a warning if this is not implemented on the platform
bool success = true;
// prefer PR_SET_DUMPABLE since that also prevents ptrace
#if defined(HAVE_PR_SET_DUMPABLE)
success = (prctl(PR_SET_DUMPABLE, 0) == 0);
#elif defined(HAVE_RLIMIT_CORE)
#if defined(HAVE_RLIMIT_CORE)
struct rlimit limit;
limit.rlim_cur = 0;
limit.rlim_max = 0;
success = (setrlimit(RLIMIT_CORE, &limit) == 0);
success = success && (setrlimit(RLIMIT_CORE, &limit) == 0);
#endif
#if defined(HAVE_PR_SET_DUMPABLE)
success = success && (prctl(PR_SET_DUMPABLE, 0) == 0);
#endif
// Mac OS X
#ifdef HAVE_PT_DENY_ATTACH
// make sure setrlimit() and ptrace() succeeded
success = success && (ptrace(PT_DENY_ATTACH, 0, 0, 0) == 0);
#endif

127
src/core/Translator.cpp Normal file
View File

@@ -0,0 +1,127 @@
/*
* Copyright (C) 2014 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Translator.h"
#include <QCoreApplication>
#include <QDir>
#include <QLibraryInfo>
#include <QLocale>
#include <QRegExp>
#include <QTranslator>
#include "config-keepassx.h"
#include "core/Config.h"
#include "core/FilePath.h"
void Translator::installTranslator()
{
QString language = config()->get("GUI/Language").toString();
if (language == "system" || language.isEmpty()) {
language = QLocale::system().name();
}
if (!installTranslator(language)) {
// English fallback still needs translations for plurals
if (!installTranslator("en_plurals")) {
qWarning("Couldn't load translations.");
}
}
installQtTranslator(language);
availableLanguages();
}
QList<QPair<QString, QString> > Translator::availableLanguages()
{
QStringList paths;
#ifdef QT_DEBUG
paths.append(QString("%1/share/translations").arg(KEEPASSX_BINARY_DIR));
#endif
paths.append(filePath()->dataPath("translations"));
QList<QPair<QString, QString> > languages;
languages.append(QPair<QString, QString>("system", "System default"));
QRegExp regExp("keepassx_([a-zA-Z_]+)\\.qm", Qt::CaseInsensitive, QRegExp::RegExp2);
Q_FOREACH (const QString& path, paths) {
Q_FOREACH (const QString& filename, QDir(path).entryList()) {
if (regExp.exactMatch(filename)) {
QString langcode = regExp.cap(1);
if (langcode == "en_plurals") {
langcode = "en";
}
QLocale locale(langcode);
QString languageStr = QLocale::languageToString(locale.language());
QString countryStr;
if (langcode.contains("_")) {
countryStr = QString(" (%1)").arg(QLocale::countryToString(locale.country()));
}
QPair<QString, QString> language(langcode, languageStr + countryStr);
languages.append(language);
}
}
}
return languages;
}
bool Translator::installTranslator(const QString& language)
{
QStringList paths;
#ifdef QT_DEBUG
paths.append(QString("%1/share/translations").arg(KEEPASSX_BINARY_DIR));
#endif
paths.append(filePath()->dataPath("translations"));
Q_FOREACH (const QString& path, paths) {
if (installTranslator(language, path)) {
return true;
}
}
return false;
}
bool Translator::installTranslator(const QString& language, const QString& path)
{
QTranslator* translator = new QTranslator(qApp);
if (translator->load(QString("keepassx_").append(language), path)) {
QCoreApplication::installTranslator(translator);
return true;
}
else {
delete translator;
return false;
}
}
bool Translator::installQtTranslator(const QString& language)
{
QTranslator* qtTranslator = new QTranslator(qApp);
if (qtTranslator->load(QString("%1/qt_%2").arg(QLibraryInfo::location(QLibraryInfo::TranslationsPath), language))) {
QCoreApplication::installTranslator(qtTranslator);
return true;
}
else {
delete qtTranslator;
return false;
}
}

36
src/core/Translator.h Normal file
View File

@@ -0,0 +1,36 @@
/*
* Copyright (C) 2014 Felix Geyer <debfx@fobos.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KEEPASSX_TRANSLATOR_H
#define KEEPASSX_TRANSLATOR_H
#include <QPair>
#include <QString>
class Translator
{
public:
static void installTranslator();
static QList<QPair<QString, QString> > availableLanguages();
private:
static bool installTranslator(const QString& language);
static bool installTranslator(const QString& language, const QString& path);
static bool installQtTranslator(const QString& language);
};
#endif // KEEPASSX_TRANSLATOR_H

View File

@@ -0,0 +1,305 @@
/****************************************************************************
**
** Copyright (C) 2013 Laszlo Papp <lpapp@kde.org>
** Copyright (C) 2013 David Faure <faure@kde.org>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qcommandlineoption.h"
#include <QSet>
class QCommandLineOptionPrivate : public QSharedData
{
public:
inline QCommandLineOptionPrivate()
{ }
void setNames(const QStringList &nameList);
//! The list of names used for this option.
QStringList names;
//! The documentation name for the value, if one is expected
//! Example: "-o <file>" means valueName == "file"
QString valueName;
//! The description used for this option.
QString description;
//! The list of default values used for this option.
QStringList defaultValues;
};
/*!
\since 5.2
\class QCommandLineOption
\brief The QCommandLineOption class defines a possible command-line option.
\inmodule QtCore
\ingroup shared
\ingroup tools
This class is used to describe an option on the command line. It allows
different ways of defining the same option with multiple aliases possible.
It is also used to describe how the option is used - it may be a flag (e.g. \c{-v})
or take an argument (e.g. \c{-o file}).
Examples:
\snippet code/src_corelib_tools_qcommandlineoption.cpp 0
\sa QCommandLineParser
*/
/*!
Constructs a command line option object with the given arguments.
The name of the option is set to \a name.
The name can be either short or long. If the name is one character in
length, it is considered a short name. Option names must not be empty,
must not start with a dash or a slash character, must not contain a \c{=}
and cannot be repeated.
The description is set to \a description. It is customary to add a "."
at the end of the description.
In addition, the \a valueName can be set if the option expects a value.
The default value for the option is set to \a defaultValue.
\sa setDescription(), setValueName(), setDefaultValues()
*/
QCommandLineOption::QCommandLineOption(const QString &name, const QString &description,
const QString &valueName,
const QString &defaultValue)
: d(new QCommandLineOptionPrivate)
{
d->setNames(QStringList(name));
setValueName(valueName);
setDescription(description);
setDefaultValue(defaultValue);
}
/*!
Constructs a command line option object with the given arguments.
This overload allows to set multiple names for the option, for instance
\c{o} and \c{output}.
The names of the option are set to \a names.
The names can be either short or long. Any name in the list that is one
character in length is a short name. Option names must not be empty,
must not start with a dash or a slash character, must not contain a \c{=}
and cannot be repeated.
The description is set to \a description. It is customary to add a "."
at the end of the description.
In addition, the \a valueName can be set if the option expects a value.
The default value for the option is set to \a defaultValue.
\sa setDescription(), setValueName(), setDefaultValues()
*/
QCommandLineOption::QCommandLineOption(const QStringList &names, const QString &description,
const QString &valueName,
const QString &defaultValue)
: d(new QCommandLineOptionPrivate)
{
d->setNames(names);
setValueName(valueName);
setDescription(description);
setDefaultValue(defaultValue);
}
/*!
Constructs a QCommandLineOption object that is a copy of the QCommandLineOption
object \a other.
\sa operator=()
*/
QCommandLineOption::QCommandLineOption(const QCommandLineOption &other)
: d(other.d)
{
}
/*!
Destroys the command line option object.
*/
QCommandLineOption::~QCommandLineOption()
{
}
/*!
Makes a copy of the \a other object and assigns it to this QCommandLineOption
object.
*/
QCommandLineOption &QCommandLineOption::operator=(const QCommandLineOption &other)
{
d = other.d;
return *this;
}
/*!
Returns the names set for this option.
*/
QStringList QCommandLineOption::names() const
{
return d->names;
}
void QCommandLineOptionPrivate::setNames(const QStringList &nameList)
{
QStringList newNames;
if (nameList.isEmpty())
qWarning("QCommandLineOption: Options must have at least one name");
Q_FOREACH (const QString &name, nameList) {
if (name.isEmpty()) {
qWarning("QCommandLineOption: Option names cannot be empty");
} else {
const QChar c = name.at(0);
if (c == QLatin1Char('-'))
qWarning("QCommandLineOption: Option names cannot start with a '-'");
else if (c == QLatin1Char('/'))
qWarning("QCommandLineOption: Option names cannot start with a '/'");
else if (name.contains(QLatin1Char('=')))
qWarning("QCommandLineOption: Option names cannot contain a '='");
else
newNames.append(name);
}
}
// commit
names = newNames;
}
/*!
Sets the name of the expected value, for the documentation, to \a valueName.
Options without a value assigned have a boolean-like behavior:
either the user specifies --option or they don't.
Options with a value assigned need to set a name for the expected value,
for the documentation of the option in the help output. An option with names \c{o} and \c{output},
and a value name of \c{file} will appear as \c{-o, --output <file>}.
Call QCommandLineParser::argument() if you expect the option to be present
only once, and QCommandLineParser::arguments() if you expect that option
to be present multiple times.
\sa valueName()
*/
void QCommandLineOption::setValueName(const QString &valueName)
{
d->valueName = valueName;
}
/*!
Returns the name of the expected value.
If empty, the option doesn't take a value.
\sa setValueName()
*/
QString QCommandLineOption::valueName() const
{
return d->valueName;
}
/*!
Sets the description used for this option to \a description.
It is customary to add a "." at the end of the description.
The description is used by QCommandLineParser::showHelp().
\sa description()
*/
void QCommandLineOption::setDescription(const QString &description)
{
d->description = description;
}
/*!
Returns the description set for this option.
\sa setDescription()
*/
QString QCommandLineOption::description() const
{
return d->description;
}
/*!
Sets the default value used for this option to \a defaultValue.
The default value is used if the user of the application does not specify
the option on the command line.
If \a defaultValue is empty, the option has no default values.
\sa defaultValues() setDefaultValues()
*/
void QCommandLineOption::setDefaultValue(const QString &defaultValue)
{
QStringList newDefaultValues;
if (!defaultValue.isEmpty()) {
newDefaultValues << defaultValue;
}
// commit:
d->defaultValues = newDefaultValues;
}
/*!
Sets the list of default values used for this option to \a defaultValues.
The default values are used if the user of the application does not specify
the option on the command line.
\sa defaultValues() setDefaultValue()
*/
void QCommandLineOption::setDefaultValues(const QStringList &defaultValues)
{
d->defaultValues = defaultValues;
}
/*!
Returns the default values set for this option.
\sa setDefaultValues()
*/
QStringList QCommandLineOption::defaultValues() const
{
return d->defaultValues;
}

View File

@@ -0,0 +1,81 @@
/****************************************************************************
**
** Copyright (C) 2013 Laszlo Papp <lpapp@kde.org>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QCOMMANDLINEOPTION_H
#define QCOMMANDLINEOPTION_H
#include <QStringList>
#include <QSharedData>
class QCommandLineOptionPrivate;
class QCommandLineOption
{
public:
explicit QCommandLineOption(const QString &name, const QString &description = QString(),
const QString &valueName = QString(),
const QString &defaultValue = QString());
explicit QCommandLineOption(const QStringList &names, const QString &description = QString(),
const QString &valueName = QString(),
const QString &defaultValue = QString());
QCommandLineOption(const QCommandLineOption &other);
~QCommandLineOption();
QCommandLineOption &operator=(const QCommandLineOption &other);
QStringList names() const;
void setValueName(const QString &name);
QString valueName() const;
void setDescription(const QString &description);
QString description() const;
void setDefaultValue(const QString &defaultValue);
void setDefaultValues(const QStringList &defaultValues);
QStringList defaultValues() const;
private:
QSharedDataPointer<QCommandLineOptionPrivate> d;
};
#endif // QCOMMANDLINEOPTION_H

View File

@@ -0,0 +1,944 @@
/****************************************************************************
**
** Copyright (C) 2013 Laszlo Papp <lpapp@kde.org>
** Copyright (C) 2013 David Faure <faure@kde.org>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qcommandlineparser.h"
#include <QCoreApplication>
#include <QHash>
#include <QVector>
#include <stdio.h>
#include <stdlib.h>
typedef QHash<QString, int> NameHash_t;
class QCommandLineParserPrivate
{
public:
inline QCommandLineParserPrivate()
: singleDashWordOptionMode(QCommandLineParser::ParseAsCompactedShortOptions),
builtinVersionOption(false),
builtinHelpOption(false),
needsParsing(true)
{ }
bool parse(const QStringList &args);
void checkParsed(const char *method);
QStringList aliases(const QString &name) const;
QString helpText() const;
bool registerFoundOption(const QString &optionName);
bool parseOptionValue(const QString &optionName, const QString &argument,
QStringList::const_iterator *argumentIterator,
QStringList::const_iterator argsEnd);
//! Error text set when parse() returns false
QString errorText;
//! The command line options used for parsing
QList<QCommandLineOption> commandLineOptionList;
//! Hash mapping option names to their offsets in commandLineOptionList and optionArgumentList.
NameHash_t nameHash;
//! Option values found (only for options with a value)
QHash<int, QStringList> optionValuesHash;
//! Names of options found on the command line.
QStringList optionNames;
//! Arguments which did not belong to any option.
QStringList positionalArgumentList;
//! Names of options which were unknown.
QStringList unknownOptionNames;
//! Application description
QString description;
//! Documentation for positional arguments
struct PositionalArgumentDefinition
{
QString name;
QString description;
QString syntax;
};
QVector<PositionalArgumentDefinition> positionalArgumentDefinitions;
//! The parsing mode for "-abc"
QCommandLineParser::SingleDashWordOptionMode singleDashWordOptionMode;
//! Whether addVersionOption was called
bool builtinVersionOption;
//! Whether addHelpOption was called
bool builtinHelpOption;
//! True if parse() needs to be called
bool needsParsing;
};
QStringList QCommandLineParserPrivate::aliases(const QString &optionName) const
{
const NameHash_t::const_iterator it = nameHash.find(optionName);
if (it == nameHash.end()) {
qWarning("QCommandLineParser: option not defined: \"%s\"", qPrintable(optionName));
return QStringList();
}
return commandLineOptionList.at(*it).names();
}
/*!
\since 5.2
\class QCommandLineParser
\inmodule QtCore
\ingroup tools
\brief The QCommandLineParser class provides a means for handling the
command line options.
QCoreApplication provides the command-line arguments as a simple list of strings.
QCommandLineParser provides the ability to define a set of options, parse the
command-line arguments, and store which options have actually been used, as
well as option values.
Any argument that isn't an option (i.e. doesn't start with a \c{-}) is stored
as a "positional argument".
The parser handles short names, long names, more than one name for the same
option, and option values.
Options on the command line are recognized as starting with a single or
double \c{-} character(s).
The option \c{-} (single dash alone) is a special case, often meaning standard
input, and not treated as an option. The parser will treat everything after the
option \c{--} (double dash) as positional arguments.
Short options are single letters. The option \c{v} would be specified by
passing \c{-v} on the command line. In the default parsing mode, short options
can be written in a compact form, for instance \c{-abc} is equivalent to \c{-a -b -c}.
The parsing mode for can be set to ParseAsLongOptions, in which case \c{-abc}
will be parsed as the long option \c{abc}.
Long options are more than one letter long and cannot be compacted together.
The long option \c{verbose} would be passed as \c{--verbose} or \c{-verbose}.
Passing values to options can be done using the assignment operator: \c{-v=value}
\c{--verbose=value}, or a space: \c{-v value} \c{--verbose value}, i.e. the next
argument is used as value (even if it starts with a \c{-}).
The parser does not support optional values - if an option is set to
require a value, one must be present. If such an option is placed last
and has no value, the option will be treated as if it had not been
specified.
The parser does not automatically support negating or disabling long options
by using the format \c{--disable-option} or \c{--no-option}. However, it is
possible to handle this case explicitly by making an option with \c{no-option}
as one of its names, and handling the option explicitly.
Example:
\snippet code/src_corelib_tools_qcommandlineparser_main.cpp 0
Known limitation: the parsing of Qt options inside QCoreApplication and subclasses
happens before QCommandLineParser exists, so it can't take it into account. This
means any option value that looks like a builtin Qt option, will be treated by
QCoreApplication as a builtin Qt option. Example: \c{--profile -reverse} will
lead to QGuiApplication seeing the -reverse option set, and removing it from
QCoreApplication::arguments() before QCommandLineParser defines the \c{profile}
option and parses the command line.
\sa QCommandLineOption, QCoreApplication
*/
/*!
Constructs a command line parser object.
*/
QCommandLineParser::QCommandLineParser()
: d(new QCommandLineParserPrivate)
{
}
/*!
Destroys the command line parser object.
*/
QCommandLineParser::~QCommandLineParser()
{
delete d;
}
/*!
\enum QCommandLineParser::SingleDashWordOptionMode
This enum describes the way the parser interprets command-line
options that use a single dash followed by multiple letters, as as \c{-abc}.
\value ParseAsCompactedShortOptions \c{-abc} is interpreted as \c{-a -b -c},
i.e. as three short options that have been compacted on the command-line,
if none of the options take a value. If \c{a} takes a value, then it
is interpreted as \c{-a bc}, i.e. the short option \c{a} followed by the value \c{bc}.
This is typically used in tools that behave like compilers, in order
to handle options such as \c{-DDEFINE=VALUE} or \c{-I/include/path}.
This is the default parsing mode. New applications are recommended to
use this mode.
\value ParseAsLongOptions \c{-abc} is interpreted as \c{--abc},
i.e. as the long option named \c{abc}. This is how Qt's own tools
(uic, rcc...) have always been parsing arguments. This mode should be
used for preserving compatibility in applications that were parsing
arguments in such a way.
\sa setSingleDashWordOptionMode()
*/
/*!
Sets the parsing mode to \a singleDashWordOptionMode.
This must be called before process() or parse().
*/
void QCommandLineParser::setSingleDashWordOptionMode(QCommandLineParser::SingleDashWordOptionMode singleDashWordOptionMode)
{
d->singleDashWordOptionMode = singleDashWordOptionMode;
}
/*!
Adds the option \a option to look for while parsing.
Returns \c true if adding the option was successful; otherwise returns \c false.
Adding the option fails if there is no name attached to the option, or
the option has a name that clashes with an option name added before.
*/
bool QCommandLineParser::addOption(const QCommandLineOption &option)
{
QStringList optionNames = option.names();
if (!optionNames.isEmpty()) {
Q_FOREACH (const QString &name, optionNames) {
if (d->nameHash.contains(name))
return false;
}
d->commandLineOptionList.append(option);
const int offset = d->commandLineOptionList.size() - 1;
Q_FOREACH (const QString &name, optionNames)
d->nameHash.insert(name, offset);
return true;
}
return false;
}
/*!
Adds the \c{-v} / \c{--version} option, which displays the version string of the application.
This option is handled automatically by QCommandLineParser.
You can set the actual version string by using QCoreApplication::setApplicationVersion().
Returns the option instance, which can be used to call isSet().
*/
QCommandLineOption QCommandLineParser::addVersionOption()
{
QCommandLineOption opt(QStringList() << "v" << "version", tr("Displays version information."));
addOption(opt);
d->builtinVersionOption = true;
return opt;
}
/*!
Adds the help option (\c{-h}, \c{--help} and \c{-?} on Windows)
This option is handled automatically by QCommandLineParser.
Remember to use setApplicationDescription to set the application description,
which will be displayed when this option is used.
Example:
\snippet code/src_corelib_tools_qcommandlineparser_main.cpp 0
Returns the option instance, which can be used to call isSet().
*/
QCommandLineOption QCommandLineParser::addHelpOption()
{
QCommandLineOption opt(QStringList()
#ifdef Q_OS_WIN
<< "?"
#endif
<< "h"
<< "help", tr("Displays this help."));
addOption(opt);
d->builtinHelpOption = true;
return opt;
}
/*!
Sets the application \a description shown by helpText().
*/
void QCommandLineParser::setApplicationDescription(const QString &description)
{
d->description = description;
}
/*!
Returns the application description set in setApplicationDescription().
*/
QString QCommandLineParser::applicationDescription() const
{
return d->description;
}
/*!
Defines an additional argument to the application, for the benefit of the help text.
The argument \a name and \a description will appear under the \c{Arguments:} section
of the help. If \a syntax is specified, it will be appended to the Usage line, otherwise
the \a name will be appended.
Example:
\snippet code/src_corelib_tools_qcommandlineparser.cpp 2
\sa addHelpOption(), helpText()
*/
void QCommandLineParser::addPositionalArgument(const QString &name, const QString &description, const QString &syntax)
{
QCommandLineParserPrivate::PositionalArgumentDefinition arg;
arg.name = name;
arg.description = description;
arg.syntax = syntax.isEmpty() ? name : syntax;
d->positionalArgumentDefinitions.append(arg);
}
/*!
Clears the definitions of additional arguments from the help text.
This is only needed for the special case of tools which support multiple commands
with different options. Once the actual command has been identified, the options
for this command can be defined, and the help text for the command can be adjusted
accordingly.
Example:
\snippet code/src_corelib_tools_qcommandlineparser.cpp 3
*/
void QCommandLineParser::clearPositionalArguments()
{
d->positionalArgumentDefinitions.clear();
}
/*!
Parses the command line \a arguments.
Most programs don't need to call this, a simple call to process() is enough.
parse() is more low-level, and only does the parsing. The application will have to
take care of the error handling, using errorText() if parse() returns \c false.
This can be useful for instance to show a graphical error message in graphical programs.
Calling parse() instead of process() can also be useful in order to ignore unknown
options temporarily, because more option definitions will be provided later on
(depending on one of the arguments), before calling process().
Don't forget that \a arguments must start with the name of the executable (ignored, though).
Returns \c false in case of a parse error (unknown option or missing value); returns \c true otherwise.
\sa process()
*/
bool QCommandLineParser::parse(const QStringList &arguments)
{
return d->parse(arguments);
}
/*!
Returns a translated error text for the user.
This should only be called when parse() returns \c false.
*/
QString QCommandLineParser::errorText() const
{
if (!d->errorText.isEmpty())
return d->errorText;
if (d->unknownOptionNames.count() == 1)
return tr("Unknown option '%1'.").arg(d->unknownOptionNames.first());
if (d->unknownOptionNames.count() > 1)
return tr("Unknown options: %1.").arg(d->unknownOptionNames.join(", "));
return QString();
}
/*!
Processes the command line \a arguments.
In addition to parsing the options (like parse()), this function also handles the builtin
options and handles errors.
The builtin options are \c{--version} if addVersionOption was called and \c{--help} if addHelpOption was called.
When invoking one of these options, or when an error happens (for instance an unknown option was
passed), the current process will then stop, using the exit() function.
\sa QCoreApplication::arguments(), parse()
*/
void QCommandLineParser::process(const QStringList &arguments)
{
if (!d->parse(arguments)) {
fprintf(stderr, "%s\n", qPrintable(errorText()));
::exit(EXIT_FAILURE);
}
if (d->builtinVersionOption && isSet("version")) {
printf("%s %s\n", qPrintable(QCoreApplication::applicationName()), qPrintable(QCoreApplication::applicationVersion()));
::exit(EXIT_SUCCESS);
}
if (d->builtinHelpOption && isSet("help"))
showHelp(EXIT_SUCCESS);
}
/*!
\overload
The command line is obtained from the QCoreApplication instance \a app.
*/
void QCommandLineParser::process(const QCoreApplication &app)
{
// QCoreApplication::arguments() is static, but the app instance must exist so we require it as parameter
Q_UNUSED(app);
process(QCoreApplication::arguments());
}
void QCommandLineParserPrivate::checkParsed(const char *method)
{
if (needsParsing)
qWarning("QCommandLineParser: call process() or parse() before %s", method);
}
/*!
\internal
Looks up the option \a optionName (found on the command line) and register it as found.
Returns \c true on success.
*/
bool QCommandLineParserPrivate::registerFoundOption(const QString &optionName)
{
if (nameHash.contains(optionName)) {
optionNames.append(optionName);
return true;
} else {
unknownOptionNames.append(optionName);
return false;
}
}
/*!
\internal
\brief Parse the value for a given option, if it was defined to expect one.
The value is taken from the next argument, or after the equal sign in \a argument.
\param optionName the short option name
\param argument the argument from the command line currently parsed. Only used for -k=value parsing.
\param argumentIterator iterator to the currently parsed argument. Incremented if the next argument contains the value.
\param argsEnd args.end(), to check if ++argumentIterator goes out of bounds
Returns \c true on success.
*/
bool QCommandLineParserPrivate::parseOptionValue(const QString &optionName, const QString &argument,
QStringList::const_iterator *argumentIterator, QStringList::const_iterator argsEnd)
{
const QLatin1Char assignChar('=');
const NameHash_t::const_iterator nameHashIt = nameHash.constFind(optionName);
if (nameHashIt != nameHash.constEnd()) {
const int assignPos = argument.indexOf(assignChar);
const NameHash_t::mapped_type optionOffset = *nameHashIt;
const bool withValue = !commandLineOptionList.at(optionOffset).valueName().isEmpty();
if (withValue) {
if (assignPos == -1) {
++(*argumentIterator);
if (*argumentIterator == argsEnd) {
errorText = QCommandLineParser::tr("Missing value after '%1'.").arg(argument);
return false;
}
optionValuesHash[optionOffset].append(*(*argumentIterator));
} else {
optionValuesHash[optionOffset].append(argument.mid(assignPos + 1));
}
} else {
if (assignPos != -1) {
errorText = QCommandLineParser::tr("Unexpected value after '%1'.").arg(argument.left(assignPos));
return false;
}
}
}
return true;
}
/*!
\internal
Parse the list of arguments \a args, and fills in
optionNames, optionValuesHash, unknownOptionNames, positionalArguments, and errorText.
Any results from a previous parse operation are removed.
The parser will not look for further options once it encounters the option
\c{--}; this does not include when \c{--} follows an option that requires a value.
*/
bool QCommandLineParserPrivate::parse(const QStringList &args)
{
needsParsing = false;
bool error = false;
const QString doubleDashString("--");
const QLatin1Char dashChar('-');
const QLatin1Char assignChar('=');
bool doubleDashFound = false;
errorText.clear();
positionalArgumentList.clear();
optionNames.clear();
unknownOptionNames.clear();
optionValuesHash.clear();
if (args.isEmpty()) {
qWarning("QCommandLineParser: argument list cannot be empty, it should contain at least the executable name");
return false;
}
QStringList::const_iterator argumentIterator = args.begin();
++argumentIterator; // skip executable name
for (; argumentIterator != args.end() ; ++argumentIterator) {
QString argument = *argumentIterator;
if (doubleDashFound) {
positionalArgumentList.append(argument);
} else if (argument.startsWith(doubleDashString)) {
if (argument.length() > 2) {
QString optionName = argument.mid(2).section(assignChar, 0, 0);
if (registerFoundOption(optionName)) {
if (!parseOptionValue(optionName, argument, &argumentIterator, args.end()))
error = true;
} else {
error = true;
}
} else {
doubleDashFound = true;
}
} else if (argument.startsWith(dashChar)) {
if (argument.size() == 1) { // single dash ("stdin")
positionalArgumentList.append(argument);
continue;
}
switch (singleDashWordOptionMode) {
case QCommandLineParser::ParseAsCompactedShortOptions:
{
QString optionName;
bool valueFound = false;
for (int pos = 1 ; pos < argument.size(); ++pos) {
optionName = argument.mid(pos, 1);
if (!registerFoundOption(optionName)) {
error = true;
} else {
const NameHash_t::const_iterator nameHashIt = nameHash.constFind(optionName);
Q_ASSERT(nameHashIt != nameHash.constEnd()); // checked by registerFoundOption
const NameHash_t::mapped_type optionOffset = *nameHashIt;
const bool withValue = !commandLineOptionList.at(optionOffset).valueName().isEmpty();
if (withValue) {
if (pos + 1 < argument.size()) {
if (argument.at(pos + 1) == assignChar)
++pos;
optionValuesHash[optionOffset].append(argument.mid(pos + 1));
valueFound = true;
}
break;
}
if (pos + 1 < argument.size() && argument.at(pos + 1) == assignChar)
break;
}
}
if (!valueFound && !parseOptionValue(optionName, argument, &argumentIterator, args.end()))
error = true;
break;
}
case QCommandLineParser::ParseAsLongOptions:
{
const QString optionName = argument.mid(1).section(assignChar, 0, 0);
if (registerFoundOption(optionName)) {
if (!parseOptionValue(optionName, argument, &argumentIterator, args.end()))
error = true;
} else {
error = true;
}
break;
}
}
} else {
positionalArgumentList.append(argument);
}
if (argumentIterator == args.end())
break;
}
return !error;
}
/*!
Checks whether the option \a name was passed to the application.
Returns \c true if the option \a name was set, false otherwise.
The name provided can be any long or short name of any option that was
added with \c addOption(). All the options names are treated as being
equivalent. If the name is not recognized or that option was not present,
false is returned.
Example:
\snippet code/src_corelib_tools_qcommandlineparser.cpp 0
*/
bool QCommandLineParser::isSet(const QString &name) const
{
d->checkParsed("isSet");
if (d->optionNames.contains(name))
return true;
const QStringList aliases = d->aliases(name);
Q_FOREACH (const QString &optionName, d->optionNames) {
if (aliases.contains(optionName))
return true;
}
return false;
}
/*!
Returns the option value found for the given option name \a optionName, or
an empty string if not found.
The name provided can be any long or short name of any option that was
added with \c addOption(). All the option names are treated as being
equivalent. If the name is not recognized or that option was not present, an
empty string is returned.
For options found by the parser, the last value found for
that option is returned. If the option wasn't specified on the command line,
the default value is returned.
An empty string is returned if the option does not take a value.
\sa values(), QCommandLineOption::setDefaultValue(), QCommandLineOption::setDefaultValues()
*/
QString QCommandLineParser::value(const QString &optionName) const
{
d->checkParsed("value");
const QStringList valueList = values(optionName);
if (!valueList.isEmpty())
return valueList.last();
return QString();
}
/*!
Returns a list of option values found for the given option name \a
optionName, or an empty list if not found.
The name provided can be any long or short name of any option that was
added with \c addOption(). All the options names are treated as being
equivalent. If the name is not recognized or that option was not present, an
empty list is returned.
For options found by the parser, the list will contain an entry for
each time the option was encountered by the parser. If the option wasn't
specified on the command line, the default values are returned.
An empty list is returned if the option does not take a value.
\sa value(), QCommandLineOption::setDefaultValue(), QCommandLineOption::setDefaultValues()
*/
QStringList QCommandLineParser::values(const QString &optionName) const
{
d->checkParsed("values");
const NameHash_t::const_iterator it = d->nameHash.constFind(optionName);
if (it != d->nameHash.constEnd()) {
const int optionOffset = *it;
QStringList values = d->optionValuesHash.value(optionOffset);
if (values.isEmpty())
values = d->commandLineOptionList.at(optionOffset).defaultValues();
return values;
}
qWarning("QCommandLineParser: option not defined: \"%s\"", qPrintable(optionName));
return QStringList();
}
/*!
\overload
Checks whether the \a option was passed to the application.
Returns \c true if the \a option was set, false otherwise.
This is the recommended way to check for options with no values.
Example:
\snippet code/src_corelib_tools_qcommandlineparser.cpp 1
*/
bool QCommandLineParser::isSet(const QCommandLineOption &option) const
{
// option.names() might be empty if the constructor failed
return !option.names().isEmpty() && isSet(option.names().first());
}
/*!
\overload
Returns the option value found for the given \a option, or
an empty string if not found.
For options found by the parser, the last value found for
that option is returned. If the option wasn't specified on the command line,
the default value is returned.
An empty string is returned if the option does not take a value.
\sa values(), QCommandLineOption::setDefaultValue(), QCommandLineOption::setDefaultValues()
*/
QString QCommandLineParser::value(const QCommandLineOption &option) const
{
return value(option.names().first());
}
/*!
\overload
Returns a list of option values found for the given \a option,
or an empty list if not found.
For options found by the parser, the list will contain an entry for
each time the option was encountered by the parser. If the option wasn't
specified on the command line, the default values are returned.
An empty list is returned if the option does not take a value.
\sa value(), QCommandLineOption::setDefaultValue(), QCommandLineOption::setDefaultValues()
*/
QStringList QCommandLineParser::values(const QCommandLineOption &option) const
{
return values(option.names().first());
}
/*!
Returns a list of positional arguments.
These are all of the arguments that were not recognized as part of an
option.
*/
QStringList QCommandLineParser::positionalArguments() const
{
d->checkParsed("positionalArguments");
return d->positionalArgumentList;
}
/*!
Returns a list of option names that were found.
This returns a list of all the recognized option names found by the
parser, in the order in which they were found. For any long options
that were in the form {--option=value}, the value part will have been
dropped.
The names in this list do not include the preceding dash characters.
Names may appear more than once in this list if they were encountered
more than once by the parser.
Any entry in the list can be used with \c value() or with
\c values() to get any relevant option values.
*/
QStringList QCommandLineParser::optionNames() const
{
d->checkParsed("optionNames");
return d->optionNames;
}
/*!
Returns a list of unknown option names.
This list will include both long an short name options that were not
recognized. For any long options that were in the form {--option=value},
the value part will have been dropped and only the long name is added.
The names in this list do not include the preceding dash characters.
Names may appear more than once in this list if they were encountered
more than once by the parser.
\sa optionNames()
*/
QStringList QCommandLineParser::unknownOptionNames() const
{
d->checkParsed("unknownOptionNames");
return d->unknownOptionNames;
}
/*!
Displays the help information, and exits the application.
This is automatically triggered by the --help option, but can also
be used to display the help when the user is not invoking the
application correctly.
The exit code is set to \a exitCode. It should be set to 0 if the
user requested to see the help, and to any other value in case of
an error.
\sa helpText()
*/
void QCommandLineParser::showHelp(int exitCode)
{
fprintf(stdout, "%s", qPrintable(d->helpText()));
::exit(exitCode);
}
/*!
Returns a string containing the complete help information.
\sa showHelp()
*/
QString QCommandLineParser::helpText() const
{
return d->helpText();
}
static QString wrapText(const QString &names, int longestOptionNameString, const QString &description)
{
const QLatin1Char nl('\n');
QString text = QString(" ") + names.leftJustified(longestOptionNameString) + QLatin1Char(' ');
const int indent = text.length();
int lineStart = 0;
int lastBreakable = -1;
const int max = 79 - indent;
int x = 0;
const int len = description.length();
for (int i = 0; i < len; ++i) {
++x;
const QChar c = description.at(i);
if (c.isSpace())
lastBreakable = i;
int breakAt = -1;
int nextLineStart = -1;
if (x > max && lastBreakable != -1) {
// time to break and we know where
breakAt = lastBreakable;
nextLineStart = lastBreakable + 1;
} else if ((x > max - 1 && lastBreakable == -1) || i == len - 1) {
// time to break but found nowhere [-> break here], or end of last line
breakAt = i + 1;
nextLineStart = breakAt;
} else if (c == nl) {
// forced break
breakAt = i;
nextLineStart = i + 1;
}
if (breakAt != -1) {
const int numChars = breakAt - lineStart;
//qDebug() << "breakAt=" << description.at(breakAt) << "breakAtSpace=" << breakAtSpace << lineStart << "to" << breakAt << description.mid(lineStart, numChars);
if (lineStart > 0)
text += QString(indent, QLatin1Char(' '));
text += description.mid(lineStart, numChars) + nl;
x = 0;
lastBreakable = -1;
lineStart = nextLineStart;
if (lineStart < len && description.at(lineStart).isSpace())
++lineStart; // don't start a line with a space
i = lineStart;
}
}
return text;
}
QString QCommandLineParserPrivate::helpText() const
{
const QLatin1Char nl('\n');
QString text;
const QString exeName = QCoreApplication::instance()->arguments().first();
QString usage = exeName;
if (!commandLineOptionList.isEmpty()) {
usage += QLatin1Char(' ');
usage += QCommandLineParser::tr("[options]");
}
Q_FOREACH (const PositionalArgumentDefinition &arg, positionalArgumentDefinitions) {
usage += QLatin1Char(' ');
usage += arg.syntax;
}
text += QCommandLineParser::tr("Usage: %1").arg(usage) + nl;
if (!description.isEmpty())
text += description + nl;
text += nl;
if (!commandLineOptionList.isEmpty())
text += QCommandLineParser::tr("Options:") + nl;
QStringList optionNameList;
int longestOptionNameString = 0;
Q_FOREACH (const QCommandLineOption &option, commandLineOptionList) {
QStringList optionNames;
Q_FOREACH (const QString &optionName, option.names()) {
if (optionName.length() == 1)
optionNames.append(QLatin1Char('-') + optionName);
else
optionNames.append(QString("--") + optionName);
}
QString optionNamesString = optionNames.join(", ");
if (!option.valueName().isEmpty())
optionNamesString += QString(" <") + option.valueName() + QLatin1Char('>');
optionNameList.append(optionNamesString);
longestOptionNameString = qMax(longestOptionNameString, optionNamesString.length());
}
++longestOptionNameString;
for (int i = 0; i < commandLineOptionList.count(); ++i) {
const QCommandLineOption &option = commandLineOptionList.at(i);
text += wrapText(optionNameList.at(i), longestOptionNameString, option.description());
}
if (!positionalArgumentDefinitions.isEmpty()) {
if (!commandLineOptionList.isEmpty())
text += nl;
text += QCommandLineParser::tr("Arguments:") + nl;
Q_FOREACH (const PositionalArgumentDefinition &arg, positionalArgumentDefinitions) {
text += wrapText(arg.name, longestOptionNameString, arg.description);
}
}
return text;
}

View File

@@ -0,0 +1,102 @@
/****************************************************************************
**
** Copyright (C) 2013 Laszlo Papp <lpapp@kde.org>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QCOMMANDLINEPARSER_H
#define QCOMMANDLINEPARSER_H
#include <QStringList>
#include <QCoreApplication>
#include "qcommandlineoption.h"
class QCommandLineParserPrivate;
class QCoreApplication;
class QCommandLineParser
{
Q_DECLARE_TR_FUNCTIONS(QCommandLineParser)
public:
QCommandLineParser();
~QCommandLineParser();
enum SingleDashWordOptionMode {
ParseAsCompactedShortOptions,
ParseAsLongOptions
};
void setSingleDashWordOptionMode(SingleDashWordOptionMode parsingMode);
bool addOption(const QCommandLineOption &commandLineOption);
QCommandLineOption addVersionOption();
QCommandLineOption addHelpOption();
void setApplicationDescription(const QString &description);
QString applicationDescription() const;
void addPositionalArgument(const QString &name, const QString &description, const QString &syntax = QString());
void clearPositionalArguments();
void process(const QStringList &arguments);
void process(const QCoreApplication &app);
bool parse(const QStringList &arguments);
QString errorText() const;
bool isSet(const QString &name) const;
QString value(const QString &name) const;
QStringList values(const QString &name) const;
bool isSet(const QCommandLineOption &option) const;
QString value(const QCommandLineOption &option) const;
QStringList values(const QCommandLineOption &option) const;
QStringList positionalArguments() const;
QStringList optionNames() const;
QStringList unknownOptionNames() const;
void showHelp(int exitCode = 0);
QString helpText() const;
private:
Q_DISABLE_COPY(QCommandLineParser)
QCommandLineParserPrivate * const d;
};
#endif // QCOMMANDLINEPARSER_H

344
src/core/qlockfile.cpp Normal file
View File

@@ -0,0 +1,344 @@
/****************************************************************************
**
** Copyright (C) 2013 David Faure <faure+bluesystems@kde.org>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qlockfile.h"
#include "qlockfile_p.h"
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
# include <QElapsedTimer>
#else
# include <QTime>
#endif
#include <QDateTime>
QT_BEGIN_NAMESPACE
/*!
\class QLockFile
\inmodule QtCore
\brief The QLockFile class provides locking between processes using a file.
\since 5.1
A lock file can be used to prevent multiple processes from accessing concurrently
the same resource. For instance, a configuration file on disk, or a socket, a port,
a region of shared memory...
Serialization is only guaranteed if all processes that access the shared resource
use QLockFile, with the same file path.
QLockFile supports two use cases:
to protect a resource for a short-term operation (e.g. verifying if a configuration
file has changed before saving new settings), and for long-lived protection of a
resource (e.g. a document opened by a user in an editor) for an indefinite amount of time.
When protecting for a short-term operation, it is acceptable to call lock() and wait
until any running operation finishes.
When protecting a resource over a long time, however, the application should always
call setStaleLockTime(0) and then tryLock() with a short timeout, in order to
warn the user that the resource is locked.
If the process holding the lock crashes, the lock file stays on disk and can prevent
any other process from accessing the shared resource, ever. For this reason, QLockFile
tries to detect such a "stale" lock file, based on the process ID written into the file,
and (in case that process ID got reused meanwhile), on the last modification time of
the lock file (30s by default, for the use case of a short-lived operation).
If the lock file is found to be stale, it will be deleted.
For the use case of protecting a resource over a long time, you should therefore call
setStaleLockTime(0), and when tryLock() returns LockFailedError, inform the user
that the document is locked, possibly using getLockInfo() for more details.
*/
/*!
\enum QLockFile::LockError
This enum describes the result of the last call to lock() or tryLock().
\value NoError The lock was acquired successfully.
\value LockFailedError The lock could not be acquired because another process holds it.
\value PermissionError The lock file could not be created, for lack of permissions
in the parent directory.
\value UnknownError Another error happened, for instance a full partition
prevented writing out the lock file.
*/
/*!
Constructs a new lock file object.
The object is created in an unlocked state.
When calling lock() or tryLock(), a lock file named \a fileName will be created,
if it doesn't already exist.
\sa lock(), unlock()
*/
QLockFile::QLockFile(const QString &fileName)
: d_ptr(new QLockFilePrivate(fileName))
{
}
/*!
Destroys the lock file object.
If the lock was acquired, this will release the lock, by deleting the lock file.
*/
QLockFile::~QLockFile()
{
unlock();
}
/*!
Sets \a staleLockTime to be the time in milliseconds after which
a lock file is considered stale.
The default value is 30000, i.e. 30 seconds.
If your application typically keeps the file locked for more than 30 seconds
(for instance while saving megabytes of data for 2 minutes), you should set
a bigger value using setStaleLockTime().
The value of \a staleLockTime is used by lock() and tryLock() in order
to determine when an existing lock file is considered stale, i.e. left over
by a crashed process. This is useful for the case where the PID got reused
meanwhile, so the only way to detect a stale lock file is by the fact that
it has been around for a long time.
\sa staleLockTime()
*/
void QLockFile::setStaleLockTime(int staleLockTime)
{
Q_D(QLockFile);
d->staleLockTime = staleLockTime;
}
/*!
Returns the time in milliseconds after which
a lock file is considered stale.
\sa setStaleLockTime()
*/
int QLockFile::staleLockTime() const
{
Q_D(const QLockFile);
return d->staleLockTime;
}
/*!
Returns \c true if the lock was acquired by this QLockFile instance,
otherwise returns \c false.
\sa lock(), unlock(), tryLock()
*/
bool QLockFile::isLocked() const
{
Q_D(const QLockFile);
return d->isLocked;
}
/*!
Creates the lock file.
If another process (or another thread) has created the lock file already,
this function will block until that process (or thread) releases it.
Calling this function multiple times on the same lock from the same
thread without unlocking first is not allowed. This function will
\e dead-lock when the file is locked recursively.
Returns \c true if the lock was acquired, false if it could not be acquired
due to an unrecoverable error, such as no permissions in the parent directory.
\sa unlock(), tryLock()
*/
bool QLockFile::lock()
{
return tryLock(-1);
}
/*!
Attempts to create the lock file. This function returns \c true if the
lock was obtained; otherwise it returns \c false. If another process (or
another thread) has created the lock file already, this function will
wait for at most \a timeout milliseconds for the lock file to become
available.
Note: Passing a negative number as the \a timeout is equivalent to
calling lock(), i.e. this function will wait forever until the lock
file can be locked if \a timeout is negative.
If the lock was obtained, it must be released with unlock()
before another process (or thread) can successfully lock it.
Calling this function multiple times on the same lock from the same
thread without unlocking first is not allowed, this function will
\e always return false when attempting to lock the file recursively.
\sa lock(), unlock()
*/
bool QLockFile::tryLock(int timeout)
{
Q_D(QLockFile);
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
QElapsedTimer timer;
#else
QTime timer;
#endif
if (timeout > 0)
timer.start();
int sleepTime = 100;
Q_FOREVER {
d->lockError = d->tryLock_sys();
switch (d->lockError) {
case NoError:
d->isLocked = true;
return true;
case PermissionError:
case UnknownError:
return false;
case LockFailedError:
if (!d->isLocked && d->isApparentlyStale()) {
// Stale lock from another thread/process
// Ensure two processes don't remove it at the same time
QLockFile rmlock(d->fileName + QLatin1String(".rmlock"));
if (rmlock.tryLock()) {
if (d->isApparentlyStale() && d->removeStaleLock())
continue;
}
}
break;
}
if (timeout == 0 || (timeout > 0 && (timer.elapsed() > timeout)))
return false;
QLockFileThread::msleep(sleepTime);
if (sleepTime < 5 * 1000)
sleepTime *= 2;
}
// not reached
return false;
}
/*!
\fn void QLockFile::unlock()
Releases the lock, by deleting the lock file.
Calling unlock() without locking the file first, does nothing.
\sa lock(), tryLock()
*/
/*!
Retrieves information about the current owner of the lock file.
If tryLock() returns \c false, and error() returns LockFailedError,
this function can be called to find out more information about the existing
lock file:
\list
\li the PID of the application (returned in \a pid)
\li the \a hostname it's running on (useful in case of networked filesystems),
\li the name of the application which created it (returned in \a appname),
\endlist
Note that tryLock() automatically deleted the file if there is no
running application with this PID, so LockFailedError can only happen if there is
an application with this PID (it could be unrelated though).
This can be used to inform users about the existing lock file and give them
the choice to delete it. After removing the file using removeStaleLockFile(),
the application can call tryLock() again.
This function returns \c true if the information could be successfully retrieved, false
if the lock file doesn't exist or doesn't contain the expected data.
This can happen if the lock file was deleted between the time where tryLock() failed
and the call to this function. Simply call tryLock() again if this happens.
*/
bool QLockFile::getLockInfo(qint64 *pid, QString *hostname, QString *appname) const
{
Q_D(const QLockFile);
return d->getLockInfo(pid, hostname, appname);
}
bool QLockFilePrivate::getLockInfo(qint64 *pid, QString *hostname, QString *appname) const
{
QFile reader(fileName);
if (!reader.open(QIODevice::ReadOnly))
return false;
QByteArray pidLine = reader.readLine();
pidLine.chop(1);
QByteArray appNameLine = reader.readLine();
appNameLine.chop(1);
QByteArray hostNameLine = reader.readLine();
hostNameLine.chop(1);
if (pidLine.isEmpty())
return false;
qint64 thePid = pidLine.toLongLong();
if (pid)
*pid = thePid;
if (appname)
*appname = QString::fromUtf8(appNameLine);
if (hostname)
*hostname = QString::fromUtf8(hostNameLine);
return thePid > 0;
}
/*!
Attempts to forcefully remove an existing lock file.
Calling this is not recommended when protecting a short-lived operation: QLockFile
already takes care of removing lock files after they are older than staleLockTime().
This method should only be called when protecting a resource for a long time, i.e.
with staleLockTime(0), and after tryLock() returned LockFailedError, and the user
agreed on removing the lock file.
Returns \c true on success, false if the lock file couldn't be removed. This happens
on Windows, when the application owning the lock is still running.
*/
bool QLockFile::removeStaleLockFile()
{
Q_D(QLockFile);
if (d->isLocked) {
qWarning("removeStaleLockFile can only be called when not holding the lock");
return false;
}
return d->removeStaleLock();
}
/*!
Returns the lock file error status.
If tryLock() returns \c false, this function can be called to find out
the reason why the locking failed.
*/
QLockFile::LockError QLockFile::error() const
{
Q_D(const QLockFile);
return d->lockError;
}
QT_END_NAMESPACE

79
src/core/qlockfile.h Normal file
View File

@@ -0,0 +1,79 @@
/****************************************************************************
**
** Copyright (C) 2013 David Faure <faure+bluesystems@kde.org>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QLOCKFILE_H
#define QLOCKFILE_H
#include <QString>
#include <QScopedPointer>
QT_BEGIN_NAMESPACE
class QLockFilePrivate;
class QLockFile
{
public:
QLockFile(const QString &fileName);
~QLockFile();
bool lock();
bool tryLock(int timeout = 0);
void unlock();
void setStaleLockTime(int);
int staleLockTime() const;
bool isLocked() const;
bool getLockInfo(qint64 *pid, QString *hostname, QString *appname) const;
bool removeStaleLockFile();
enum LockError {
NoError = 0,
LockFailedError = 1,
PermissionError = 2,
UnknownError = 3
};
LockError error() const;
protected:
QScopedPointer<QLockFilePrivate> d_ptr;
private:
Q_DECLARE_PRIVATE(QLockFile)
Q_DISABLE_COPY(QLockFile)
};
QT_END_NAMESPACE
#endif // QLOCKFILE_H

101
src/core/qlockfile_p.h Normal file
View File

@@ -0,0 +1,101 @@
/****************************************************************************
**
** Copyright (C) 2013 David Faure <faure+bluesystems@kde.org>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QLOCKFILE_P_H
#define QLOCKFILE_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include "qlockfile.h"
#include <QFile>
#include <QThread>
#ifdef Q_OS_WIN
#include <qt_windows.h>
#endif
QT_BEGIN_NAMESPACE
class QLockFileThread : public QThread
{
public:
static void msleep(unsigned long msecs) { QThread::msleep(msecs); }
};
class QLockFilePrivate
{
public:
QLockFilePrivate(const QString &fn)
: fileName(fn),
#ifdef Q_OS_WIN
fileHandle(INVALID_HANDLE_VALUE),
#else
fileHandle(-1),
#endif
staleLockTime(30 * 1000), // 30 seconds
lockError(QLockFile::NoError),
isLocked(false)
{
}
QLockFile::LockError tryLock_sys();
bool removeStaleLock();
bool getLockInfo(qint64 *pid, QString *hostname, QString *appname) const;
// Returns \c true if the lock belongs to dead PID, or is old.
// The attempt to delete it will tell us if it was really stale or not, though.
bool isApparentlyStale() const;
static QString processNameByPid(qint64 pid);
QString fileName;
#ifdef Q_OS_WIN
Qt::HANDLE fileHandle;
#else
int fileHandle;
#endif
int staleLockTime; // "int milliseconds" is big enough for 24 days
QLockFile::LockError lockError;
bool isLocked;
};
QT_END_NAMESPACE
#endif /* QLOCKFILE_P_H */

244
src/core/qlockfile_unix.cpp Normal file
View File

@@ -0,0 +1,244 @@
/****************************************************************************
**
** Copyright (C) 2013 David Faure <faure+bluesystems@kde.org>
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qlockfile_p.h"
#include <QTemporaryFile>
#include <QCoreApplication>
#include <QFileInfo>
#include <QDebug>
#include <QDateTime>
#include <sys/file.h> // flock
#include <sys/types.h> // kill
#include <signal.h> // kill
#include <unistd.h> // gethostname
#include <errno.h>
#if defined(Q_OS_MAC)
# include <libproc.h>
#elif defined(Q_OS_LINUX)
# include <unistd.h>
# include <cstdio>
#endif
QT_BEGIN_NAMESPACE
#define EINTR_LOOP(var, cmd) \
do { \
var = cmd; \
} while (var == -1 && errno == EINTR)
// don't call QT_OPEN or ::open
// call qt_safe_open
static inline int qt_safe_open(const char *pathname, int flags, mode_t mode = 0777)
{
#ifdef O_CLOEXEC
flags |= O_CLOEXEC;
#endif
int fd;
EINTR_LOOP(fd, ::open(pathname, flags, mode));
// unknown flags are ignored, so we have no way of verifying if
// O_CLOEXEC was accepted
if (fd != -1)
::fcntl(fd, F_SETFD, FD_CLOEXEC);
return fd;
}
static inline qint64 qt_safe_write(int fd, const void *data, qint64 len)
{
qint64 ret = 0;
EINTR_LOOP(ret, ::write(fd, data, len));
return ret;
}
static QByteArray localHostName() // from QHostInfo::localHostName(), modified to return a QByteArray
{
QByteArray hostName(512, Qt::Uninitialized);
if (gethostname(hostName.data(), hostName.size()) == -1)
return QByteArray();
hostName.truncate(strlen(hostName.data()));
return hostName;
}
// ### merge into qt_safe_write?
static qint64 qt_write_loop(int fd, const char *data, qint64 len)
{
qint64 pos = 0;
while (pos < len) {
const qint64 ret = qt_safe_write(fd, data + pos, len - pos);
if (ret == -1) // e.g. partition full
return pos;
pos += ret;
}
return pos;
}
static bool setNativeLocks(int fd)
{
#if defined(LOCK_EX) && defined(LOCK_NB)
if (flock(fd, LOCK_EX | LOCK_NB) == -1) // other threads, and other processes on a local fs
return false;
#endif
struct flock flockData;
flockData.l_type = F_WRLCK;
flockData.l_whence = SEEK_SET;
flockData.l_start = 0;
flockData.l_len = 0; // 0 = entire file
flockData.l_pid = getpid();
if (fcntl(fd, F_SETLK, &flockData) == -1) // for networked filesystems
return false;
return true;
}
QLockFile::LockError QLockFilePrivate::tryLock_sys()
{
// Assemble data, to write in a single call to write
// (otherwise we'd have to check every write call)
// Use operator% from the fast builder to avoid multiple memory allocations.
QByteArray fileData = QByteArray::number(QCoreApplication::applicationPid()) + '\n'
+ QCoreApplication::applicationName().toUtf8() + '\n'
+ localHostName() + '\n';
const QByteArray lockFileName = QFile::encodeName(fileName);
const int fd = qt_safe_open(lockFileName.constData(), O_WRONLY | O_CREAT | O_EXCL, 0644);
if (fd < 0) {
switch (errno) {
case EEXIST:
return QLockFile::LockFailedError;
case EACCES:
case EROFS:
return QLockFile::PermissionError;
default:
return QLockFile::UnknownError;
}
}
// Ensure nobody else can delete the file while we have it
if (!setNativeLocks(fd))
qWarning() << "setNativeLocks failed:" << strerror(errno);
if (qt_write_loop(fd, fileData.constData(), fileData.size()) < fileData.size()) {
close(fd);
if (!QFile::remove(fileName))
qWarning("QLockFile: Could not remove our own lock file %s.", qPrintable(fileName));
return QLockFile::UnknownError; // partition full
}
// We hold the lock, continue.
fileHandle = fd;
return QLockFile::NoError;
}
bool QLockFilePrivate::removeStaleLock()
{
const QByteArray lockFileName = QFile::encodeName(fileName);
const int fd = qt_safe_open(lockFileName.constData(), O_WRONLY, 0644);
if (fd < 0) // gone already?
return false;
#ifdef Q_OS_MAC
// ugly workaround: ignore setNativeLocks() result on Mac since it's broken there
setNativeLocks(fd);
bool success = (::unlink(lockFileName) == 0);
#else
bool success = setNativeLocks(fd) && (::unlink(lockFileName) == 0);
#endif
close(fd);
return success;
}
bool QLockFilePrivate::isApparentlyStale() const
{
qint64 pid;
QString hostname, appname;
if (getLockInfo(&pid, &hostname, &appname)) {
if (hostname.isEmpty() || hostname == QString::fromLocal8Bit(localHostName())) {
if (::kill(pid, 0) == -1 && errno == ESRCH)
return true; // PID doesn't exist anymore
const QString processName = processNameByPid(pid);
if (!processName.isEmpty()) {
QFileInfo fi(appname);
if (fi.isSymLink())
fi.setFile(fi.symLinkTarget());
if (processName.toLower() != fi.fileName().toLower())
return true; // PID got reused by a different application.
}
}
}
const qint64 age = QFileInfo(fileName).lastModified().secsTo(QDateTime::currentDateTime()) * 1000;
return staleLockTime > 0 && age > staleLockTime;
}
QString QLockFilePrivate::processNameByPid(qint64 pid)
{
#if defined(Q_OS_MAC)
char name[1024];
proc_name(pid, name, sizeof(name) / sizeof(char));
return QFile::decodeName(name);
#elif defined(Q_OS_LINUX)
if (!QFile::exists(QString("/proc/version")))
return QString();
char exePath[64];
char buf[PATH_MAX + 1];
sprintf(exePath, "/proc/%lld/exe", pid);
size_t len = static_cast<size_t>(readlink(exePath, buf, sizeof(buf)));
if (len >= sizeof(buf)) {
// The pid is gone. Return some invalid process name to fail the test.
return QString("/ERROR/");
}
buf[len] = 0;
return QFileInfo(QFile::decodeName(buf)).fileName();
#else
return QString();
#endif
}
void QLockFile::unlock()
{
Q_D(QLockFile);
if (!d->isLocked)
return;
close(d->fileHandle);
d->fileHandle = -1;
if (!QFile::remove(d->fileName)) {
qWarning() << "Could not remove our own lock file" << d->fileName << "maybe permissions changed meanwhile?";
// This is bad because other users of this lock file will now have to wait for the stale-lock-timeout...
}
d->lockError = QLockFile::NoError;
d->isLocked = false;
}
QT_END_NAMESPACE

227
src/core/qlockfile_win.cpp Normal file
View File

@@ -0,0 +1,227 @@
/****************************************************************************
**
** Copyright (C) 2013 David Faure <faure+bluesystems@kde.org>
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef _UNICODE
#define _UNICODE
#endif
#ifndef UNICODE
#define UNICODE
#endif
#include "qlockfile_p.h"
#include <qt_windows.h>
#include <QCoreApplication>
#include <QDir>
#include <QFileInfo>
#include <QDateTime>
#include <QDebug>
QT_BEGIN_NAMESPACE
static inline QByteArray localHostName()
{
return qgetenv("COMPUTERNAME");
}
static inline bool fileExists(const wchar_t *fileName)
{
WIN32_FILE_ATTRIBUTE_DATA data;
return GetFileAttributesEx(fileName, GetFileExInfoStandard, &data);
}
QLockFile::LockError QLockFilePrivate::tryLock_sys()
{
const ushort* nativePath = QDir::toNativeSeparators(fileName).utf16();
// When writing, allow others to read.
// When reading, QFile will allow others to read and write, all good.
// Adding FILE_SHARE_DELETE would allow forceful deletion of stale files,
// but Windows doesn't allow recreating it while this handle is open anyway,
// so this would only create confusion (can't lock, but no lock file to read from).
const DWORD dwShareMode = FILE_SHARE_READ;
#ifndef Q_OS_WINRT
SECURITY_ATTRIBUTES securityAtts = { sizeof(SECURITY_ATTRIBUTES), NULL, FALSE };
HANDLE fh = CreateFile((const wchar_t*)nativePath,
GENERIC_WRITE,
dwShareMode,
&securityAtts,
CREATE_NEW, // error if already exists
FILE_ATTRIBUTE_NORMAL,
NULL);
#else // !Q_OS_WINRT
HANDLE fh = CreateFile2((const wchar_t*)nativePath,
GENERIC_WRITE,
dwShareMode,
CREATE_NEW, // error if already exists
NULL);
#endif // Q_OS_WINRT
if (fh == INVALID_HANDLE_VALUE) {
const DWORD lastError = GetLastError();
switch (lastError) {
case ERROR_SHARING_VIOLATION:
case ERROR_ALREADY_EXISTS:
case ERROR_FILE_EXISTS:
return QLockFile::LockFailedError;
case ERROR_ACCESS_DENIED:
// readonly file, or file still in use by another process.
// Assume the latter if the file exists, since we don't create it readonly.
return fileExists((const wchar_t*)nativePath)
? QLockFile::LockFailedError
: QLockFile::PermissionError;
default:
qWarning() << "Got unexpected locking error" << lastError;
return QLockFile::UnknownError;
}
}
// We hold the lock, continue.
fileHandle = fh;
// Assemble data, to write in a single call to write
// (otherwise we'd have to check every write call)
QByteArray fileData;
fileData += QByteArray::number(QCoreApplication::applicationPid());
fileData += '\n';
fileData += QCoreApplication::applicationName().toUtf8();
fileData += '\n';
fileData += localHostName();
fileData += '\n';
DWORD bytesWritten = 0;
QLockFile::LockError error = QLockFile::NoError;
if (!WriteFile(fh, fileData.constData(), fileData.size(), &bytesWritten, NULL) || !FlushFileBuffers(fh))
error = QLockFile::UnknownError; // partition full
return error;
}
bool QLockFilePrivate::removeStaleLock()
{
// QFile::remove fails on Windows if the other process is still using the file, so it's not stale.
return QFile::remove(fileName);
}
bool QLockFilePrivate::isApparentlyStale() const
{
qint64 pid;
QString hostname, appname;
// On WinRT there seems to be no way of obtaining information about other
// processes due to sandboxing
#ifndef Q_OS_WINRT
if (getLockInfo(&pid, &hostname, &appname)) {
if (hostname.isEmpty() || hostname == QString::fromLocal8Bit(localHostName())) {
HANDLE procHandle = ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
if (!procHandle)
return true;
// We got a handle but check if process is still alive
DWORD dwR = ::WaitForSingleObject(procHandle, 0);
::CloseHandle(procHandle);
if (dwR == WAIT_TIMEOUT)
return true;
const QString processName = processNameByPid(pid);
if (!processName.isEmpty() && processName != appname)
return true; // PID got reused by a different application.
}
}
#else // !Q_OS_WINRT
Q_UNUSED(pid);
Q_UNUSED(hostname);
Q_UNUSED(appname);
#endif // Q_OS_WINRT
const qint64 age = QFileInfo(fileName).lastModified().msecsTo(QDateTime::currentDateTime());
return staleLockTime > 0 && age > staleLockTime;
}
QString QLockFilePrivate::processNameByPid(qint64 pid)
{
#if !defined(Q_OS_WINRT) && !defined(Q_OS_WINCE)
typedef DWORD (WINAPI *GetModuleFileNameExFunc)(HANDLE, HMODULE, LPTSTR, DWORD);
HMODULE hPsapi = LoadLibraryA("psapi");
if (!hPsapi)
return QString();
GetModuleFileNameExFunc qGetModuleFileNameEx
= (GetModuleFileNameExFunc)GetProcAddress(hPsapi, "GetModuleFileNameExW");
if (!qGetModuleFileNameEx) {
FreeLibrary(hPsapi);
return QString();
}
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, DWORD(pid));
if (!hProcess) {
FreeLibrary(hPsapi);
return QString();
}
wchar_t buf[MAX_PATH];
const DWORD length = qGetModuleFileNameEx(hProcess, NULL, buf, sizeof(buf) / sizeof(wchar_t));
CloseHandle(hProcess);
FreeLibrary(hPsapi);
if (!length)
return QString();
QString name = QString::fromWCharArray(buf, length);
int i = name.lastIndexOf(QLatin1Char('\\'));
if (i >= 0)
name.remove(0, i + 1);
i = name.lastIndexOf(QLatin1Char('.'));
if (i >= 0)
name.truncate(i);
return name;
#else
Q_UNUSED(pid);
return QString();
#endif
}
void QLockFile::unlock()
{
Q_D(QLockFile);
if (!d->isLocked)
return;
CloseHandle(d->fileHandle);
int attempts = 0;
static const int maxAttempts = 500; // 500ms
while (!QFile::remove(d->fileName) && ++attempts < maxAttempts) {
// Someone is reading the lock file right now (on Windows this prevents deleting it).
QLockFileThread::msleep(1);
}
if (attempts == maxAttempts) {
qWarning() << "Could not remove our own lock file" << d->fileName << ". Either other users of the lock file are reading it constantly for 500 ms, or we (no longer) have permissions to delete the file";
// This is bad because other users of this lock file will now have to wait for the stale-lock-timeout...
}
d->lockError = QLockFile::NoError;
d->isLocked = false;
}
QT_END_NAMESPACE

View File

@@ -46,6 +46,12 @@
#include <QFileInfo>
#include <QTemporaryFile>
#ifdef Q_OS_WIN
# include <windows.h>
#else
# include <unistd.h>
#endif
QSaveFilePrivate::QSaveFilePrivate()
: tempFile(0), error(QFile::NoError)
{
@@ -279,8 +285,19 @@ bool QSaveFile::commit()
Q_D(QSaveFile);
if (!d->tempFile)
return false;
Q_ASSERT(isOpen());
QIODevice::close(); // flush and close
if (!isOpen()) {
qWarning("QSaveFile::commit: File (%s) is not open", qPrintable(fileName()));
return false;
}
flush();
#ifdef Q_OS_WIN
FlushFileBuffers(reinterpret_cast<HANDLE>(handle()));
#elif defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0
fdatasync(d->tempFile->handle());
#else
fsync(d->tempFile->handle());
#endif
QIODevice::close();
if (d->error != QFile::NoError) {
d->tempFile->remove();
unsetError();

View File

@@ -21,8 +21,14 @@
#include <gcrypt.h>
bool Crypto::m_initalized(false);
#include "config-keepassx.h"
#include "crypto/CryptoHash.h"
#include "crypto/SymmetricCipher.h"
bool Crypto::m_initalized(false);
QString Crypto::m_errorStr;
#if !defined(GCRYPT_VERSION_NUMBER) || (GCRYPT_VERSION_NUMBER < 0x010600)
static int gcry_qt_mutex_init(void** p_sys)
{
*p_sys = new QMutex();
@@ -57,23 +63,39 @@ static const struct gcry_thread_cbs gcry_threads_qt =
gcry_qt_mutex_unlock,
0, 0, 0, 0, 0, 0, 0, 0
};
#endif
Crypto::Crypto()
{
}
void Crypto::init()
bool Crypto::init()
{
if (m_initalized) {
qWarning("Crypto::init: already initalized");
return;
return true;
}
// libgcrypt >= 1.6 doesn't allow custom thread callbacks anymore.
#if !defined(GCRYPT_VERSION_NUMBER) || (GCRYPT_VERSION_NUMBER < 0x010600)
gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_qt);
#endif
gcry_check_version(0);
gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
if (!checkAlgorithms()) {
return false;
}
// has to be set before testing Crypto classes
m_initalized = true;
if (!selfTest()) {
m_initalized = false;
return false;
}
return true;
}
bool Crypto::initalized()
@@ -81,7 +103,222 @@ bool Crypto::initalized()
return m_initalized;
}
bool Crypto::selfTest()
QString Crypto::errorString()
{
return m_errorStr;
}
bool Crypto::backendSelfTest()
{
return (gcry_control(GCRYCTL_SELFTEST) == 0);
}
bool Crypto::checkAlgorithms()
{
if (gcry_cipher_algo_info(GCRY_CIPHER_AES256, GCRYCTL_TEST_ALGO, Q_NULLPTR, Q_NULLPTR) != 0) {
m_errorStr = "GCRY_CIPHER_AES256 not found.";
qWarning("Crypto::checkAlgorithms: %s", qPrintable(m_errorStr));
return false;
}
if (gcry_cipher_algo_info(GCRY_CIPHER_TWOFISH, GCRYCTL_TEST_ALGO, Q_NULLPTR, Q_NULLPTR) != 0) {
m_errorStr = "GCRY_CIPHER_TWOFISH not found.";
qWarning("Crypto::checkAlgorithms: %s", qPrintable(m_errorStr));
return false;
}
#ifdef GCRYPT_HAS_SALSA20
if (gcry_cipher_algo_info(GCRY_CIPHER_SALSA20, GCRYCTL_TEST_ALGO, Q_NULLPTR, Q_NULLPTR) != 0) {
m_errorStr = "GCRY_CIPHER_SALSA20 not found.";
qWarning("Crypto::checkAlgorithms: %s", qPrintable(m_errorStr));
return false;
}
#endif
if (gcry_md_test_algo(GCRY_MD_SHA256) != 0) {
m_errorStr = "GCRY_MD_SHA256 not found.";
qWarning("Crypto::checkAlgorithms: %s", qPrintable(m_errorStr));
return false;
}
return true;
}
bool Crypto::selfTest()
{
return testSha256() && testAes256Cbc() && testAes256Ecb() && testTwofish() && testSalsa20();
}
void Crypto::raiseError(const QString& str)
{
m_errorStr = str;
qWarning("Crypto::selfTest: %s", qPrintable(m_errorStr));
}
bool Crypto::testSha256()
{
QByteArray sha256Test = CryptoHash::hash("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
CryptoHash::Sha256);
if (sha256Test != QByteArray::fromHex("248D6A61D20638B8E5C026930C3E6039A33CE45964FF2167F6ECEDD419DB06C1")) {
raiseError("SHA-256 mismatch.");
return false;
}
return true;
}
bool Crypto::testAes256Cbc()
{
QByteArray key = QByteArray::fromHex("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
QByteArray iv = QByteArray::fromHex("000102030405060708090a0b0c0d0e0f");
QByteArray plainText = QByteArray::fromHex("6bc1bee22e409f96e93d7e117393172a");
plainText.append(QByteArray::fromHex("ae2d8a571e03ac9c9eb76fac45af8e51"));
QByteArray cipherText = QByteArray::fromHex("f58c4c04d6e5f1ba779eabfb5f7bfbd6");
cipherText.append(QByteArray::fromHex("9cfc4e967edb808d679f777bc6702c7d"));
bool ok;
SymmetricCipher aes256Encrypt(SymmetricCipher::Aes256, SymmetricCipher::Cbc, SymmetricCipher::Encrypt);
if (!aes256Encrypt.init(key, iv)) {
raiseError(aes256Encrypt.errorString());
return false;
}
QByteArray encryptedText = aes256Encrypt.process(plainText, &ok);
if (!ok) {
raiseError(aes256Encrypt.errorString());
return false;
}
if (encryptedText != cipherText) {
raiseError("AES-256 CBC encryption mismatch.");
return false;
}
SymmetricCipher aes256Descrypt(SymmetricCipher::Aes256, SymmetricCipher::Cbc, SymmetricCipher::Decrypt);
if (!aes256Descrypt.init(key, iv)) {
raiseError(aes256Descrypt.errorString());
return false;
}
QByteArray decryptedText = aes256Descrypt.process(cipherText, &ok);
if (!ok) {
raiseError(aes256Descrypt.errorString());
return false;
}
if (decryptedText != plainText) {
raiseError("AES-256 CBC decryption mismatch.");
return false;
}
return true;
}
bool Crypto::testAes256Ecb()
{
QByteArray key = QByteArray::fromHex("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F");
QByteArray iv = QByteArray::fromHex("00000000000000000000000000000000");
QByteArray plainText = QByteArray::fromHex("00112233445566778899AABBCCDDEEFF");
plainText.append(QByteArray::fromHex("00112233445566778899AABBCCDDEEFF"));
QByteArray cipherText = QByteArray::fromHex("8EA2B7CA516745BFEAFC49904B496089");
cipherText.append(QByteArray::fromHex("8EA2B7CA516745BFEAFC49904B496089"));
bool ok;
SymmetricCipher aes256Encrypt(SymmetricCipher::Aes256, SymmetricCipher::Ecb, SymmetricCipher::Encrypt);
if (!aes256Encrypt.init(key, iv)) {
raiseError(aes256Encrypt.errorString());
return false;
}
QByteArray encryptedText = aes256Encrypt.process(plainText, &ok);
if (!ok) {
raiseError(aes256Encrypt.errorString());
return false;
}
if (encryptedText != cipherText) {
raiseError("AES-256 ECB encryption mismatch.");
return false;
}
SymmetricCipher aes256Descrypt(SymmetricCipher::Aes256, SymmetricCipher::Ecb, SymmetricCipher::Decrypt);
if (!aes256Descrypt.init(key, iv)) {
raiseError(aes256Descrypt.errorString());
return false;
}
QByteArray decryptedText = aes256Descrypt.process(cipherText, &ok);
if (!ok) {
raiseError(aes256Descrypt.errorString());
return false;
}
if (decryptedText != plainText) {
raiseError("AES-256 ECB decryption mismatch.");
return false;
}
return true;
}
bool Crypto::testTwofish()
{
QByteArray key = QByteArray::fromHex("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
QByteArray iv = QByteArray::fromHex("000102030405060708090a0b0c0d0e0f");
QByteArray plainText = QByteArray::fromHex("6bc1bee22e409f96e93d7e117393172a");
plainText.append(QByteArray::fromHex("ae2d8a571e03ac9c9eb76fac45af8e51"));
QByteArray cipherText = QByteArray::fromHex("e0227c3cc80f3cb1b2ed847cc6f57d3c");
cipherText.append(QByteArray::fromHex("657b1e7960b30fb7c8d62e72ae37c3a0"));
bool ok;
SymmetricCipher twofishEncrypt(SymmetricCipher::Twofish, SymmetricCipher::Cbc, SymmetricCipher::Encrypt);
if (!twofishEncrypt.init(key, iv)) {
raiseError(twofishEncrypt.errorString());
return false;
}
QByteArray encryptedText = twofishEncrypt.process(plainText, &ok);
if (!ok) {
raiseError(twofishEncrypt.errorString());
return false;
}
if (encryptedText != cipherText) {
raiseError("Twofish encryption mismatch.");
return false;
}
SymmetricCipher twofishDecrypt(SymmetricCipher::Twofish, SymmetricCipher::Cbc, SymmetricCipher::Decrypt);
if (!twofishDecrypt.init(key, iv)) {
raiseError(twofishEncrypt.errorString());
return false;
}
QByteArray decryptedText = twofishDecrypt.process(cipherText, &ok);
if (!ok) {
raiseError(twofishDecrypt.errorString());
return false;
}
if (decryptedText != plainText) {
raiseError("Twofish encryption mismatch.");
return false;
}
return true;
}
bool Crypto::testSalsa20()
{
QByteArray salsa20Key = QByteArray::fromHex("F3F4F5F6F7F8F9FAFBFCFDFEFF000102030405060708090A0B0C0D0E0F101112");
QByteArray salsa20iv = QByteArray::fromHex("0000000000000000");
QByteArray salsa20Plain = QByteArray::fromHex("00000000000000000000000000000000");
QByteArray salsa20Cipher = QByteArray::fromHex("B4C0AFA503BE7FC29A62058166D56F8F");
bool ok;
SymmetricCipher salsa20Stream(SymmetricCipher::Salsa20, SymmetricCipher::Stream,
SymmetricCipher::Encrypt);
if (!salsa20Stream.init(salsa20Key, salsa20iv)) {
raiseError(salsa20Stream.errorString());
return false;
}
QByteArray salsaProcessed = salsa20Stream.process(salsa20Plain, &ok);
if (!ok) {
raiseError(salsa20Stream.errorString());
return false;
}
if (salsaProcessed != salsa20Cipher) {
raiseError("Salsa20 stream cipher mismatch.");
return false;
}
return true;
}

View File

@@ -18,18 +18,31 @@
#ifndef KEEPASSX_CRYPTO_H
#define KEEPASSX_CRYPTO_H
#include <QString>
#include "core/Global.h"
class Crypto
{
public:
static void init();
static bool init();
static bool initalized();
static bool selfTest();
static bool backendSelfTest();
static QString errorString();
private:
Crypto();
static bool checkAlgorithms();
static bool selfTest();
static void raiseError(const QString& str);
static bool testSha256();
static bool testAes256Cbc();
static bool testAes256Ecb();
static bool testTwofish();
static bool testSalsa20();
static bool m_initalized;
static QString m_errorStr;
};
#endif // KEEPASSX_CRYPTO_H

View File

@@ -49,6 +49,7 @@ CryptoHash::CryptoHash(CryptoHash::Algorithm algo)
gcry_error_t error = gcry_md_open(&d->ctx, algoGcrypt, 0);
Q_ASSERT(error == 0); // TODO: error handling
Q_UNUSED(error);
d->hashLen = gcry_md_get_algo_dlen(algoGcrypt);
}

View File

@@ -17,32 +17,59 @@
#include "SymmetricCipher.h"
#include "config-keepassx.h"
#include "crypto/SymmetricCipherGcrypt.h"
#include "crypto/SymmetricCipherSalsa20.h"
SymmetricCipher::SymmetricCipher(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode,
SymmetricCipher::Direction direction, const QByteArray& key, const QByteArray& iv)
SymmetricCipher::Direction direction)
: m_backend(createBackend(algo, mode, direction))
, m_initialized(false)
{
m_backend->init();
m_backend->setKey(key);
m_backend->setIv(iv);
}
SymmetricCipher::~SymmetricCipher()
{
}
bool SymmetricCipher::init(const QByteArray& key, const QByteArray& iv)
{
if (!m_backend->init()) {
return false;
}
if (!m_backend->setKey(key)) {
return false;
}
if (!m_backend->setIv(iv)) {
return false;
}
m_initialized = true;
return true;
}
bool SymmetricCipher::isInitalized() const
{
return m_initialized;
}
SymmetricCipherBackend* SymmetricCipher::createBackend(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode,
SymmetricCipher::Direction direction)
{
switch (algo) {
case SymmetricCipher::Aes256:
case SymmetricCipher::Twofish:
#if defined(GCRYPT_HAS_SALSA20)
case SymmetricCipher::Salsa20:
#endif
return new SymmetricCipherGcrypt(algo, mode, direction);
#if !defined(GCRYPT_HAS_SALSA20)
case SymmetricCipher::Salsa20:
return new SymmetricCipherSalsa20(algo, mode, direction);
#endif
default:
Q_ASSERT(false);
@@ -50,12 +77,17 @@ SymmetricCipherBackend* SymmetricCipher::createBackend(SymmetricCipher::Algorith
}
}
void SymmetricCipher::reset()
bool SymmetricCipher::reset()
{
m_backend->reset();
return m_backend->reset();
}
int SymmetricCipher::blockSize() const
{
return m_backend->blockSize();
}
QString SymmetricCipher::errorString() const
{
return m_backend->errorString();
}

View File

@@ -20,6 +20,7 @@
#include <QByteArray>
#include <QScopedPointer>
#include <QString>
#include "core/Global.h"
#include "crypto/SymmetricCipherBackend.h"
@@ -48,30 +49,35 @@ public:
};
SymmetricCipher(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode,
SymmetricCipher::Direction direction, const QByteArray& key, const QByteArray& iv);
SymmetricCipher::Direction direction);
~SymmetricCipher();
inline QByteArray process(const QByteArray& data) {
return m_backend->process(data);
bool init(const QByteArray& key, const QByteArray& iv);
bool isInitalized() const;
inline QByteArray process(const QByteArray& data, bool* ok) {
return m_backend->process(data, ok);
}
inline void processInPlace(QByteArray& data) {
m_backend->processInPlace(data);
inline bool processInPlace(QByteArray& data) Q_REQUIRED_RESULT {
return m_backend->processInPlace(data);
}
inline void processInPlace(QByteArray& data, quint64 rounds) {
inline bool processInPlace(QByteArray& data, quint64 rounds) Q_REQUIRED_RESULT {
Q_ASSERT(rounds > 0);
m_backend->processInPlace(data, rounds);
return m_backend->processInPlace(data, rounds);
}
void reset();
bool reset();
int blockSize() const;
QString errorString() const;
private:
static SymmetricCipherBackend* createBackend(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode,
SymmetricCipher::Direction direction);
const QScopedPointer<SymmetricCipherBackend> m_backend;
bool m_initialized;
Q_DISABLE_COPY(SymmetricCipher)
};

Some files were not shown because too many files have changed in this diff Show More