Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
System
KPMCore
Commits
e483bab0
Commit
e483bab0
authored
Feb 20, 2022
by
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
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/core/fstab.cpp
View file @
e483bab0
...
...
@@ -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
());
}
src/core/fstab.h
View file @
e483bab0
...
...
@@ -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
src/util/externalcommand.cpp
View file @
e483bab0
...
...
@@ -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
);
}
...
...
src/util/externalcommand.h
View file @
e483bab0
...
...
@@ -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
&
file
Path
,
const
QString
&
fileContents
);
// similar to writeData but creates a new file
bool
writeFstab
(
const
QByteArray
&
file
Contents
);
/**< @param cmd the command to run */
void
setCommand
(
const
QString
&
cmd
);
...
...
src/util/externalcommandhelper.cpp
View file @
e483bab0
...
...
@@ -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
;
...
...
src/util/externalcommandhelper.h
View file @
e483bab0
...
...
@@ -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
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment