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

@ -22,6 +22,7 @@
#include "core/Group.h"
#include "core/Merger.h"
#include "core/Metadata.h"
#include "format/KdbxXmlReader.h"
#include "format/KeePass2Reader.h"
#include "format/KeePass2Writer.h"
#include "keys/FileKey.h"
@ -332,6 +333,24 @@ bool Database::extract(QByteArray& xmlOutput, QString* error)
return true;
}
bool Database::import(const QString& xmlExportPath, QString* error)
{
KdbxXmlReader reader(KeePass2::FILE_VERSION_4);
QFile file(xmlExportPath);
file.open(QIODevice::ReadOnly);
reader.readDatabase(&file, this);
if (reader.hasError()) {
if (error) {
*error = reader.errorString();
}
return false;
}
return true;
}
/**
* Remove the old backup and replace it with a new one
* backups are named <filename>.old.<extension>