Vala和PolicyKit [英] Vala and PolicyKit

查看:58
本文介绍了Vala和PolicyKit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Vala中创建一个基于GTK +的简单应用程序,该应用程序应该能够写入系统目录,因此需要root访问权限.我意识到授予完全root用户访问权限是一个坏主意,因此我需要一种获取临时特权的方法.

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.

从理论上讲,PolicyKit D-Bus服务是完成这项工作的工具,但我不知道如何使用它,更不用说在Vala代码中了.任何见识将不胜感激.

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.

更新: 我做了一些进一步的挖掘.我的出发点是.因此,基本上我需要找出如何使这些解决方案适应PolicyKit.为此,有必要找到PolicyKit的D-Bus接口.我在此处. (奇怪的是,我在本地/usr/share/dbus-1/interfaces 文件夹中找不到它.)但是现在我不知道如何继续.

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.

推荐答案

polkit参考手册包含一些很好的信息,包括有关编写polkit应用程序.

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

您可能应该考虑使用 libpolkit-gobject-1 库.您可以直接使用GIR,也可以使用vapigen生成VAPI(我建议这样做). 此处是我刚刚生成的.我对API并不是很熟悉,但是使用C API引用作为找出Vala API的参考非常容易.

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.

这篇关于Vala和PolicyKit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆