Commit e483bab0 authored by Andrius Štikonas's avatar Andrius Štikonas
Browse files

Restrict CreateFile method to WriteFstab method in polkit helper.

parent 27b85117
Pipeline #140247 passed with stage
in 1 minute and 20 seconds
......@@ -295,7 +295,7 @@ static void writeEntry(QTextStream& s, const FstabEntry& entry, std::array<unsig
<< entry.comment() << "\n";
}
bool writeMountpoints(const FstabEntryList& fstabEntries, const QString& filename)
bool writeMountpoints(const FstabEntryList& fstabEntries)
{
QString fstabContents;
QTextStream out(&fstabContents);
......@@ -306,5 +306,5 @@ bool writeMountpoints(const FstabEntryList& fstabEntries, const QString& filenam
writeEntry(out, e, columnWidth);
ExternalCommand cmd;
return cmd.createFile(fstabContents.toLocal8Bit(), filename);
return cmd.writeFstab(fstabContents.toLocal8Bit());
}
......@@ -116,6 +116,6 @@ QString unescapeSpaces(const QString& mountPoint);
LIBKPMCORE_EXPORT FstabEntryList readFstabEntries(const QString& fstabPath = QStringLiteral("/etc/fstab"));
LIBKPMCORE_EXPORT QStringList possibleMountPoints(const QString& deviceNode, const QString& fstabPath = QStringLiteral("/etc/fstab"));
LIBKPMCORE_EXPORT bool writeMountpoints(const FstabEntryList& fstabEntries, const QString& filename = QStringLiteral("/etc/fstab"));
LIBKPMCORE_EXPORT bool writeMountpoints(const FstabEntryList& fstabEntries);
#endif
......@@ -231,13 +231,13 @@ bool ExternalCommand::writeData(Report& commandReport, const QByteArray& buffer,
return waitForDbusReply(pcall);
}
bool ExternalCommand::createFile(const QByteArray& fileContents, const QString& filePath)
bool ExternalCommand::writeFstab(const QByteArray& fileContents)
{
auto interface = helperInterface();
if (!interface)
return false;
QDBusPendingCall pcall = interface->CreateFile(filePath, fileContents);
QDBusPendingCall pcall = interface->WriteFstab(fileContents);
return waitForDbusReply(pcall);
}
......
......@@ -57,7 +57,7 @@ public:
bool copyBlocks(const CopySource& source, CopyTarget& target);
QByteArray readData(const CopySourceDevice& source);
bool writeData(Report& commandReport, const QByteArray& buffer, const QString& deviceNode, const quint64 firstByte); // same as copyBlocks but from QByteArray
bool createFile(const QByteArray& filePath, const QString& fileContents); // similar to writeData but creates a new file
bool writeFstab(const QByteArray& fileContents);
/**< @param cmd the command to run */
void setCommand(const QString& cmd);
......
......@@ -126,19 +126,15 @@ bool ExternalCommandHelper::writeData(QFile& device, const QByteArray& buffer, c
}
/** Creates a new file with given contents.
@param filePath file to write to
@param fileContents the data that we write
@return true on success
*/
bool ExternalCommandHelper::CreateFile(const QString &filePath, const QByteArray& fileContents)
bool ExternalCommandHelper::WriteFstab(const QByteArray& fileContents)
{
if (!isCallerAuthorized()) {
return false;
}
// Do not allow using this helper for writing to arbitrary location
if ( filePath != QStringLiteral("/etc/fstab") )
return false;
QString filePath = QStringLiteral("/etc/fstab");
QFile device(filePath);
auto flags = QIODevice::WriteOnly | QIODevice::Unbuffered;
......
......@@ -43,7 +43,7 @@ public Q_SLOTS:
const QString& targetDevice, const qint64 targetOffset, const qint64 blockSize);
Q_SCRIPTABLE QByteArray ReadData(const QString& device, const qint64 offset, const qint64 length);
Q_SCRIPTABLE bool WriteData(const QByteArray& buffer, const QString& targetDevice, const qint64 targetOffset);
Q_SCRIPTABLE bool CreateFile(const QString& filePath, const QByteArray& fileContents);
Q_SCRIPTABLE bool WriteFstab(const QByteArray& fileContents);
private:
bool isCallerAuthorized();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment