Re: Need help regarding qfile management inside KAuth helper
- Date: Wed, 14 Jun 2017 22:53:46 +0200
- From: Christoph Feck <cfeck@xxxxxxx>
- Subject: Re: Need help regarding qfile management inside KAuth helper
On 14.06.2017 18:40, chinmoy ranjan wrote:
I am working on the GSOC project "Polkit support in KIO". As a part of this
project right now I am trying to add KAuth support to the 'copy' method of
file ioslave. My initial plan was to let KAuth helper open the files
requiring elevated privilege for reading and/or writing and then pass the
file descriptor or maybe the file pointer back to the copy method of file
ioslave which would then perform rest of the copy operation.
I tried different approaches but none seemed to work. Here's what I've
tried so far:
1> Created a QFile pointer to the restricted file, created a QVariant from
the file pointer and then tried to pass it to KAuth helper. KIO compiled
successfully but when tried to copy some read-restricted files QVariant
complained about not being able to load/save the type. So I googled the
warning and tried every possible solution involving qRegisterMetaType but
still got no luck.
2> Casted the QFile to a QObject and then repeated the above steps but got
same results as before (read nothing).
3> Tried reinterpret_cast'ing the QFile pointer to quintptr. I was hoping
to retrieve the file pointer inside the helper and then opening the file
for read/write operation using that pointer. But when I used this method
the helper crashed.
4> One of my latest attempts was to get the file descriptor and then pass
it to Kauth helper and use it there to open the file. KIO compiled but the
copy operation simply didn't worked. Little bit of googling showed
something called QDBusUnixFileDescriptor but I don't know how it works and
wasn't able to find any examples on internet either.
5> In my most recent attempt I decided to pass only the file path and let
the helper create, open and read the contents of file. And after reading is
finished pass the data that has been stored in a QByteArray buffer to the
copy method. Surprisingly it worked for text files. For binary files it
seemed to work at first but actually the data was corrupt. Moreover this
method was extremely slow.
So can anyone tell me how to send file descriptor or file pointer over
dbus( since kauth helper and the ioslave interact using dbus)?
Or if anyone could point out a better (faster and secure) approach for the
said task? Links to example programs, code snippet, relevant docs or forum
threads would be of great help.
thanks for taking up this huge task!
You cannot share file IDs or pointers between processes. If you do not
want a single process do both the reads as well as the writes, you would
have to pass the file data between the processes using pipes, shared
memory, or any other form of IPC.