Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vala and PolicyKit

I'm creating a simple GTK+ based application in Vala, which should be able to write into system directories, so it needs root access. I realize that giving full root access is a bad idea, so I need a way to gain temporary privileges.

In theory, the PolicyKit D-Bus service is the tool for the job, but I have no idea how to use it, let alone in Vala code. Any insight would be appreciated.

update: I have done some further digging. My starting point was this. So basically what I need is finding out how to adapt these solutions to PolicyKit. For this, it is necessary to find the D-Bus interface of PolicyKit. I found it here. (Strangely I didn't find it in my local /usr/share/dbus-1/interfaces folder.) But now I have no idea how to continue.

like image 423
meskobalazs Avatar asked Dec 17 '25 18:12

meskobalazs


1 Answers

The polkit Reference Manual contains some good information, including a high-level overview on writing polkit applications.

Instead of using the D-Bus interface directly, you should probably consider using the libpolkit-gobject-1 library. You can use the GIR directly, or generate a VAPI (which I would recommend) with vapigen. Here is one I just generated. I'm not really familiar with the API, but it is very easy to use a C API reference as a reference to figure out the Vala API.

like image 165
nemequ Avatar answered Dec 20 '25 09:12

nemequ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!