Add support for passing Unix file descriptors
Needs ReviewPublic

Authored by volkov on Sep 26 2019, 4:22 PM.

Details

Reviewers
fvogt
chinmoyr
cfeck
security-team
Group Reviewers
Frameworks
Summary

Introduce UnixFileDescriptor class, which holds a copy of a file
descriptor. Actually it's a wrapper around QDBusUnixFileDescriptor
that hides the use of QtDBus from client code.

Currently arguments to/from a helper are passed as QVariantMap,
encoded as QByteArray. To support passing of file descriptors,
separate them into their own QVariantMap, and pass arguments as
QVariantList consisting of the QByteArray blob of data arguments
and the file descriptors map ({un}packedArguments() functions).

Diff Detail

Repository
R283 KAuth
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 17106
Build 17124: arc lint + arc unit
volkov created this revision.Sep 26 2019, 4:22 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptSep 26 2019, 4:22 PM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
volkov requested review of this revision.Sep 26 2019, 4:22 PM
fvogt requested changes to this revision.Sep 26 2019, 5:00 PM

Unfortunately, this breaks public API and ABI by modifying KAuth::ActionReply.

I'm not sure whether there has to be any compatibility for the DBus API, but I guess not (logging out and back in should suffice to make sure the backend used is the same).

I wonder why you made a wrapper around QDBusUnixFileDescriptor, does it not work inside a QVariant OOTB?

This revision now requires changes to proceed.Sep 26 2019, 5:00 PM

DBus is an internal dependency for KAuth. With the wrapper users don't have to link with QtDBus.

volkov updated this revision to Diff 66946.Sep 27 2019, 1:13 PM

fix breaking API and ABI of KAuth::ActionReply

aacid added a subscriber: aacid.Sep 27 2019, 7:51 PM
aacid added inline comments.
src/HelperProxy.cpp
25 ↗(On Diff #66946)

i don't think we should have dbus stuff in HelperProxy, dbus stuff should be in DBusHelperProxy, no?

This comment was removed by volkov.
src/HelperProxy.cpp
25 ↗(On Diff #66946)

yes, thanks

volkov updated this revision to Diff 66968.Sep 27 2019, 8:15 PM

moved dbus stuff to DBusHelperProxy

volkov edited the summary of this revision. (Show Details)Sep 27 2019, 8:17 PM
aacid added inline comments.Sep 28 2019, 6:59 AM
src/kauthunixfiledescriptor.h
33

Does this class really need to be exported and its header installed?

Seems like this is implementation detail? Who would use this header?

volkov added inline comments.Sep 28 2019, 8:49 AM
src/kauthunixfiledescriptor.h
33

It's needed to mark file descriptors in QVariantMap.
Usage example:

ActionReply reply;
QVariantMap data;
auto variantFd = QVariant::fromValue(UnixFileDescriptor(saveFile.handle()));
data.insert(QStringLiteral("fd"), variantFd);
reply.setData(data);
return reply;

Applications are supposed to do that?

Yes, UnixFileDescriptor allows to use existing methods Action::setArguments() and ActionReply::setData().

Without UnixFileDescriptor you could try to write

int fd = ...
Action action(...);
action.addArgument(QStringLiteral("fd"), fd);

but then KAuth won't be able to detect that it'a file descriptor and will pass it to a helper as int.

Without UnixFileDescriptor you could try to write

int fd = ...
Action action(...);
action.addArgument(QStringLiteral("fd"), fd);

but then KAuth won't be able to detect that it'a file descriptor and will pass it to a helper as int.

Would it make more sense to add a new function

Action::addFileDescriptor(const QString &, int)?

This way we don't have to expose UnixFileDescriptor to the world

volkov added a comment.Oct 1 2019, 7:35 AM

It will require adding the following methods:

Action::setFileDescriptors()
Action::addFileDescriptor()
Action::fileDescriptors()
ActionReply::setFileDescriptors()
ActionReply::addFileDescriptor()
ActionReply::fileDescriptors()

and

ExecuteJob::fileDescriptors()
ExecuteJob::newFileDescriptors()

with the condition that for progress data they can be used only with direct signal-slot connections,
because without UnixFileDescriptor we cannot guarantee the open state of file descriptors.
It doesn't seem better than exposing this class.

aacid added a comment.Oct 7 2019, 10:00 PM

ok, fair enough.

Am i correct in understanding this breaks the wire-protocol for the dbus messages?

Are we sure that's fine?