CLI: Add Import XML command (#3572)

The CLI now contains an "import" command that creates a new database from the specified XML export. The new database is in kdbx 4 format, and does not currently accept a keyfile in database creation.

This change is required to create new databases from XML backups.

Fixes #2458
This commit is contained in:
Jacob Sachs 2019-10-14 08:37:26 -04:00 committed by Jonathan White
parent 82cfedfa43
commit dbe15d32e5
14 changed files with 2127 additions and 1904 deletions

View file

@ -127,7 +127,7 @@ namespace Utils
}
if (isPasswordProtected) {
out << QObject::tr("Insert password to unlock %1: ").arg(databaseFilename) << flush;
out << QObject::tr("Enter password to unlock %1: ").arg(databaseFilename) << flush;
QString line = Utils::getPassword(outputDescriptor);
auto passwordKey = QSharedPointer<PasswordKey>::create();
passwordKey->setPassword(line);
@ -217,6 +217,28 @@ namespace Utils
return line;
}
/**
* Read optional password from stdin.
*
* @return Pointer to the PasswordKey or null if passwordkey is skipped
* by user
*/
QSharedPointer<PasswordKey> getPasswordFromStdin()
{
QSharedPointer<PasswordKey> passwordKey;
QTextStream out(Utils::STDOUT, QIODevice::WriteOnly);
out << QObject::tr("Enter password to encrypt database (optional): ");
out.flush();
QString password = Utils::getPassword();
if (!password.isEmpty()) {
passwordKey = QSharedPointer<PasswordKey>(new PasswordKey(password));
}
return passwordKey;
}
/**
* A valid and running event loop is needed to use the global QClipboard,
* so we need to use this from the CLI.