Support LUKS mounting.
This commit is contained in:
parent
17eb5e51e5
commit
cdf57075f9
|
@ -18,9 +18,12 @@
|
||||||
|
|
||||||
#include "fs/luks.h"
|
#include "fs/luks.h"
|
||||||
|
|
||||||
|
#include "gui/decryptluksdialog.h"
|
||||||
|
|
||||||
#include "util/capacity.h"
|
#include "util/capacity.h"
|
||||||
#include "util/externalcommand.h"
|
#include "util/externalcommand.h"
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
@ -83,11 +86,37 @@ qint64 luks::minCapacity() const
|
||||||
return 3 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB);
|
return 3 * Capacity::unitFactor(Capacity::Byte, Capacity::MiB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString luks::mountTitle() const
|
||||||
|
{
|
||||||
|
return i18nc("@title:menu", "Decrypt");
|
||||||
|
}
|
||||||
|
|
||||||
QString luks::unmountTitle() const
|
QString luks::unmountTitle() const
|
||||||
{
|
{
|
||||||
return i18nc("@title:menu", "Deactivate");
|
return i18nc("@title:menu", "Deactivate");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool luks::mount(const QString& deviceNode)
|
||||||
|
{
|
||||||
|
QPointer<DecryptLuksDialog> dlg = new DecryptLuksDialog(0, deviceNode); //TODO: parent widget instead of 0
|
||||||
|
|
||||||
|
if (dlg->exec() == QDialog::Accepted)
|
||||||
|
{
|
||||||
|
std::vector<QString> commands;
|
||||||
|
commands.push_back(QStringLiteral("echo"));
|
||||||
|
commands.push_back(QStringLiteral("cryptsetup"));
|
||||||
|
std::vector<QStringList> args;
|
||||||
|
args.push_back(QStringList() << dlg->luksPassphrase().text());
|
||||||
|
args.push_back(QStringList() << QStringLiteral("luksOpen") << deviceNode << dlg->luksName().text());
|
||||||
|
ExternalCommand cmd(commands, args);
|
||||||
|
delete dlg;
|
||||||
|
return cmd.run(-1) && cmd.exitCode() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete dlg;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool luks::unmount(const QString& deviceNode)
|
bool luks::unmount(const QString& deviceNode)
|
||||||
{
|
{
|
||||||
ExternalCommand cmd(QStringLiteral("cryptsetup"), QStringList() << QStringLiteral("luksClose") << mapperName(deviceNode));
|
ExternalCommand cmd(QStringLiteral("cryptsetup"), QStringList() << QStringLiteral("luksClose") << mapperName(deviceNode));
|
||||||
|
@ -111,6 +140,16 @@ bool luks::updateUUID(Report& report, const QString& deviceNode) const
|
||||||
return cmd.run(-1) && cmd.exitCode() == 0;
|
return cmd.run(-1) && cmd.exitCode() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool luks::canMount(const QString&) const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool luks::canUnmount(const QString&) const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
QString luks::mapperName(const QString& deviceNode)
|
QString luks::mapperName(const QString& deviceNode)
|
||||||
{
|
{
|
||||||
ExternalCommand cmd(QStringLiteral("find"), QStringList() << QStringLiteral("/dev/mapper/") << QStringLiteral("-exec") << QStringLiteral("cryptsetup") << QStringLiteral("status") << QStringLiteral("{}") << QStringLiteral(";"));
|
ExternalCommand cmd(QStringLiteral("find"), QStringList() << QStringLiteral("/dev/mapper/") << QStringLiteral("-exec") << QStringLiteral("cryptsetup") << QStringLiteral("status") << QStringLiteral("{}") << QStringLiteral(";"));
|
||||||
|
|
|
@ -85,11 +85,12 @@ public:
|
||||||
virtual QString readUUID(const QString& deviceNode) const;
|
virtual QString readUUID(const QString& deviceNode) const;
|
||||||
virtual bool updateUUID(Report& report, const QString& deviceNode) const;
|
virtual bool updateUUID(Report& report, const QString& deviceNode) const;
|
||||||
|
|
||||||
virtual bool canUnmount(const QString&) const {
|
virtual bool canMount(const QString&) const;
|
||||||
return true;
|
virtual bool canUnmount(const QString&) const;
|
||||||
};
|
|
||||||
|
|
||||||
|
virtual bool mount(const QString& deviceNode);
|
||||||
virtual bool unmount(const QString& deviceNode);
|
virtual bool unmount(const QString& deviceNode);
|
||||||
|
virtual QString mountTitle() const;
|
||||||
virtual QString unmountTitle() const;
|
virtual QString unmountTitle() const;
|
||||||
|
|
||||||
static QString mapperName(const QString& deviceNode);
|
static QString mapperName(const QString& deviceNode);
|
||||||
|
|
Loading…
Reference in New Issue