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);
|
return waitForDbusReply(pcall);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ExternalCommand::createFile(const QByteArray& buffer, const QString& deviceNode)
|
bool ExternalCommand::createFile(const QByteArray& fileContents, const QString& filePath)
|
||||||
{
|
{
|
||||||
auto interface = helperInterface();
|
auto interface = helperInterface();
|
||||||
if (!interface)
|
if (!interface)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QDBusPendingCall pcall = interface->createFile(buffer, deviceNode);
|
QDBusPendingCall pcall = interface->createFile(filePath, fileContents);
|
||||||
return waitForDbusReply(pcall);
|
return waitForDbusReply(pcall);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ public:
|
||||||
public:
|
public:
|
||||||
bool copyBlocks(const CopySource& source, CopyTarget& target);
|
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 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 */
|
/**< @param cmd the command to run */
|
||||||
void setCommand(const QString& cmd);
|
void setCommand(const QString& cmd);
|
||||||
|
|
|
@ -132,6 +132,10 @@ bool ExternalCommandHelper::createFile(const QString &filePath, const QByteArray
|
||||||
if (!isCallerAuthorized()) {
|
if (!isCallerAuthorized()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// Do not allow using this helper for writing to arbitrary location
|
||||||
|
if ( !filePath.contains(QStringLiteral("/etc/fstab")) )
|
||||||
|
return false;
|
||||||
|
|
||||||
QFile device(filePath);
|
QFile device(filePath);
|
||||||
|
|
||||||
auto flags = QIODevice::WriteOnly | QIODevice::Unbuffered;
|
auto flags = QIODevice::WriteOnly | QIODevice::Unbuffered;
|
||||||
|
@ -253,18 +257,6 @@ bool ExternalCommandHelper::writeData(const QByteArray& buffer, const QString& t
|
||||||
return writeData(targetDevice, buffer, targetFirstByte);
|
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)
|
QVariantMap ExternalCommandHelper::start(const QString& command, const QStringList& arguments, const QByteArray& input, const int processChannelMode)
|
||||||
{
|
{
|
||||||
if (!isCallerAuthorized()) {
|
if (!isCallerAuthorized()) {
|
||||||
|
|
|
@ -34,13 +34,12 @@ public:
|
||||||
ExternalCommandHelper();
|
ExternalCommandHelper();
|
||||||
bool readData(const QString& sourceDevice, QByteArray& buffer, const qint64 offset, const qint64 size);
|
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 writeData(const QString& targetDevice, const QByteArray& buffer, const qint64 offset);
|
||||||
bool createFile(const QString& filePath, const QByteArray& fileContents);
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
Q_SCRIPTABLE QVariantMap start(const QString& command, const QStringList& arguments, const QByteArray& input, const int processChannelMode);
|
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 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 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:
|
private:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue