Simplify createFile function, it was checking for authorization twice.
This commit is contained in:
parent
2dff59260c
commit
a2ee82e021
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
Loading…
Reference in New Issue