Remove "mv" command from allowed external command list
This commit is contained in:
parent
77add45499
commit
9fa20fb1e2
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "core/fstab.h"
|
#include "core/fstab.h"
|
||||||
#include "util/externalcommand.h"
|
#include "util/externalcommand.h"
|
||||||
|
#include "util/report.h"
|
||||||
|
|
||||||
#if defined(Q_OS_LINUX)
|
#if defined(Q_OS_LINUX)
|
||||||
#include <blkid/blkid.h>
|
#include <blkid/blkid.h>
|
||||||
|
@ -228,9 +229,8 @@ static void parseFsSpec(const QString& m_fsSpec, FstabEntry::Type& m_entryType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void writeEntry(QFile& output, const FstabEntry& entry)
|
static void writeEntry(QTextStream& s, const FstabEntry& entry)
|
||||||
{
|
{
|
||||||
QTextStream s(&output);
|
|
||||||
if (entry.entryType() == FstabEntry::Type::comment) {
|
if (entry.entryType() == FstabEntry::Type::comment) {
|
||||||
s << entry.comment() << "\n";
|
s << entry.comment() << "\n";
|
||||||
return;
|
return;
|
||||||
|
@ -256,32 +256,13 @@ static void writeEntry(QFile& output, const FstabEntry& entry)
|
||||||
|
|
||||||
bool writeMountpoints(const FstabEntryList& fstabEntries, const QString& filename)
|
bool writeMountpoints(const FstabEntryList& fstabEntries, const QString& filename)
|
||||||
{
|
{
|
||||||
QTemporaryFile out;
|
Report report(nullptr);
|
||||||
out.setAutoRemove(false);
|
QByteArray fstabContents;
|
||||||
|
QTextStream out(&fstabContents);
|
||||||
|
|
||||||
if (!out.open()) {
|
for (const auto &e : fstabEntries)
|
||||||
qWarning() << "could not open output file " << out.fileName();
|
writeEntry(out, e);
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
for (const auto &e : fstabEntries)
|
|
||||||
writeEntry(out, e);
|
|
||||||
|
|
||||||
out.close();
|
ExternalCommand cmd;
|
||||||
const QString bakFilename = QStringLiteral("%1.bak").arg(filename);
|
return cmd.writeData(report, fstabContents, filename, 0);
|
||||||
ExternalCommand mvCmd(QStringLiteral("mv"), { filename, bakFilename } );
|
|
||||||
|
|
||||||
if ( !(mvCmd.run(-1) && mvCmd.exitCode() == 0) ) {
|
|
||||||
qWarning() << "could not backup " << filename << " to " << bakFilename;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ExternalCommand mvCmd2(QStringLiteral("mv"), { out.fileName(), filename } );
|
|
||||||
|
|
||||||
if ( !(mvCmd2.run(-1) && mvCmd2.exitCode() == 0) ) {
|
|
||||||
qWarning() << "could not move " << out.fileName() << " to " << filename;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,19 +151,14 @@ Device* SfdiskBackend::scanDevice(const QString& deviceNode)
|
||||||
QRegularExpressionMatchIterator i = re.globalMatch(content);
|
QRegularExpressionMatchIterator i = re.globalMatch(content);
|
||||||
|
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
|
|
||||||
QRegularExpressionMatch reMatch = i.next();
|
QRegularExpressionMatch reMatch = i.next();
|
||||||
|
|
||||||
QString name = reMatch.captured(1);
|
QString name = reMatch.captured(1);
|
||||||
|
|
||||||
if ((QStringLiteral("/dev/md") + name) == deviceNode) {
|
if ((QStringLiteral("/dev/md") + name) == deviceNode) {
|
||||||
Log(Log::Level::information) << xi18nc("@info:status", "Software RAID Device found: %1", deviceNode);
|
Log(Log::Level::information) << xi18nc("@info:status", "Software RAID Device found: %1", deviceNode);
|
||||||
|
|
||||||
d = new SoftwareRAID( QStringLiteral("md") + name, SoftwareRAID::Status::Active );
|
d = new SoftwareRAID( QStringLiteral("md") + name, SoftwareRAID::Status::Active );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,6 @@
|
||||||
#define KPMCORE_EXTERNALCOMMAND_WHITELIST_H
|
#define KPMCORE_EXTERNALCOMMAND_WHITELIST_H
|
||||||
|
|
||||||
QString allowedCommands[] = {
|
QString allowedCommands[] = {
|
||||||
// TODO try to remove these later
|
|
||||||
QStringLiteral("mv"),
|
|
||||||
|
|
||||||
// TODO no root needed
|
// TODO no root needed
|
||||||
QStringLiteral("lsblk"),
|
QStringLiteral("lsblk"),
|
||||||
QStringLiteral("udevadm"),
|
QStringLiteral("udevadm"),
|
||||||
|
|
Loading…
Reference in New Issue