diff --git a/src/util/externalcommand.cpp b/src/util/externalcommand.cpp index 21e8123..90147c1 100644 --- a/src/util/externalcommand.cpp +++ b/src/util/externalcommand.cpp @@ -209,13 +209,13 @@ bool ExternalCommand::writeData(Report& commandReport, const QByteArray& buffer, return waitForDbusReply(pcall); } -bool ExternalCommand::createFile(const QByteArray& buffer, const QString& deviceNode) +bool ExternalCommand::createFile(const QByteArray& fileContents, const QString& filePath) { auto interface = helperInterface(); if (!interface) return false; - QDBusPendingCall pcall = interface->createFile(buffer, deviceNode); + QDBusPendingCall pcall = interface->createFile(filePath, fileContents); return waitForDbusReply(pcall); } diff --git a/src/util/externalcommand.h b/src/util/externalcommand.h index 224ebb4..05f7dc1 100644 --- a/src/util/externalcommand.h +++ b/src/util/externalcommand.h @@ -57,7 +57,7 @@ public: public: bool copyBlocks(const CopySource& source, CopyTarget& target); bool writeData(Report& commandReport, const QByteArray& buffer, const QString& deviceNode, const quint64 firstByte); // same as copyBlocks but from QByteArray - bool createFile(const QByteArray& buffer, const QString& deviceNode); // similar to writeData but creates a new file + bool createFile(const QByteArray& filePath, const QString& fileContents); // similar to writeData but creates a new file /**< @param cmd the command to run */ void setCommand(const QString& cmd); diff --git a/src/util/externalcommandhelper.cpp b/src/util/externalcommandhelper.cpp index e9e9b03..4b85a5e 100644 --- a/src/util/externalcommandhelper.cpp +++ b/src/util/externalcommandhelper.cpp @@ -132,6 +132,10 @@ bool ExternalCommandHelper::createFile(const QString &filePath, const QByteArray if (!isCallerAuthorized()) { return false; } + // Do not allow using this helper for writing to arbitrary location + if ( !filePath.contains(QStringLiteral("/etc/fstab")) ) + return false; + QFile device(filePath); auto flags = QIODevice::WriteOnly | QIODevice::Unbuffered; @@ -253,18 +257,6 @@ bool ExternalCommandHelper::writeData(const QByteArray& buffer, const QString& t return writeData(targetDevice, buffer, targetFirstByte); } -bool ExternalCommandHelper::createFile(const QByteArray& fileContents, const QString& filePath) -{ - if (!isCallerAuthorized()) { - return false; - } - // Do not allow using this helper for writing to arbitrary location - if ( !filePath.contains(QStringLiteral("/etc/fstab")) ) - return false; - - return createFile(filePath, fileContents); -} - QVariantMap ExternalCommandHelper::start(const QString& command, const QStringList& arguments, const QByteArray& input, const int processChannelMode) { if (!isCallerAuthorized()) { diff --git a/src/util/externalcommandhelper.h b/src/util/externalcommandhelper.h index 10ba3f5..2eb6050 100644 --- a/src/util/externalcommandhelper.h +++ b/src/util/externalcommandhelper.h @@ -34,13 +34,12 @@ public: ExternalCommandHelper(); bool readData(const QString& sourceDevice, QByteArray& buffer, const qint64 offset, const qint64 size); bool writeData(const QString& targetDevice, const QByteArray& buffer, const qint64 offset); - bool createFile(const QString& filePath, const QByteArray& fileContents); public Q_SLOTS: Q_SCRIPTABLE QVariantMap start(const QString& command, const QStringList& arguments, const QByteArray& input, const int processChannelMode); Q_SCRIPTABLE QVariantMap copyblocks(const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize); Q_SCRIPTABLE bool writeData(const QByteArray& buffer, const QString& targetDevice, const qint64 targetFirstByte); - Q_SCRIPTABLE bool createFile(const QByteArray& fileContents, const QString& filePath); + Q_SCRIPTABLE bool createFile(const QString& filePath, const QByteArray& fileContents); private: