惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News and Events Feed by Topic
S
SegmentFault 最新的问题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
Jina AI
Jina AI
H
Help Net Security
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
L
LangChain Blog
Recorded Future
Recorded Future
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ
GbyAI
GbyAI
B
Blog RSS Feed
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
M
MIT News - Artificial intelligence
爱范儿
爱范儿
V
V2EX
Microsoft Azure Blog
Microsoft Azure Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Y
Y Combinator Blog
B
Blog
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
W
WeLiveSecurity
MongoDB | Blog
MongoDB | Blog
Cloudbric
Cloudbric
N
News and Events Feed by Topic
The Cloudflare Blog
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
D
DataBreaches.Net
博客园 - 【当耐特】
T
Troy Hunt's Blog
V
Visual Studio Blog
V2EX - 技术
V2EX - 技术
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google Online Security Blog
Google Online Security Blog
The GitHub Blog
The GitHub Blog

Qt for linux – 魔帆博客

QDBus之路----------Hello DBus | 魔帆博客
QDBus之路----------Polkit-Qt5 | 魔帆博客
夏叶随风 · 2017-05-26 · via Qt for linux – 魔帆博客

没看上一篇的需要看上一篇 QDBus之路———-Hello DBus

我们都知道linux下有些惭怍需要root运行,然后通常直接sudo,但是,对于linux小白用户而言,总不能一运行软件就弹出要求用户sudo xxx重新运行软件吧,估计别人连sudo是啥都不知道

所以,软件要进行root操作,就需要利用polkit

其实polkit也没那么神圣,不过是读取对应的配置文件来验证用户下罢了。

实现root操作的大致原理就是写一个daemon,所以的root操作都写到这里,然后用dbus吧接口暴露出去,不过daemon暴露出去的接口都需要自行调用polkit(这里使用的是qt风格的polkit-qt5)进行验证,验证通过再继续操作

然后这个daemon还要在systemBus注册dbus服务,并且要手动sudo运行或者让他开机自启(dbus运行时自启动死活启动不了,sessionBus上注册能自启,但是明明指定了root用户结果还是普通用户运行,没权限)

polkit验证请求

Authority::Result result;
// 第一个参数是需要验证的action,和规则文件写的保持一致
result = Authority::instance()->checkAuthorizationSync(actionId, UnixProcessSubject(applicationPid),
                                                       Authority::AllowUserInteraction);
if (result == Authority::Yes) {
    //验证通过,进行root操作
}else {
    //验证不通过,不进行任何操作并return
}

源码:

https://github.com/1377195627/polkit-qt-example.git