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

推荐订阅源

T
The Blog of Author Tim Ferriss
S
Securelist
D
Docker
The Register - Security
The Register - Security
GbyAI
GbyAI
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
罗磊的独立博客
博客园 - 【当耐特】
F
Full Disclosure
WordPress大学
WordPress大学
腾讯CDC
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
I
InfoQ
MyScale Blog
MyScale Blog
量子位
Cyberwarzone
Cyberwarzone
博客园 - 三生石上(FineUI控件)
The Hacker News
The Hacker News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
博客园_首页
H
Help Net Security
K
Kaspersky official blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
The Cloudflare Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
爱范儿
爱范儿
P
Privacy International News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog RSS Feed

夏叶随风 – 魔帆博客

QDBus之路----------Hello DBus | 魔帆博客 校园网客户端 for linux解决方案 | 魔帆博客 为Linux应用说句公道话 | 魔帆博客 JetBrains全家桶翻译插件 | 魔帆博客 漫画趣解 Linux 内核构造 | 魔帆博客 chrome-dev v58以上版本开启自带flash插件 | 魔帆博客 用c实现动态数组(int)精简版 | 魔帆博客
QDBus之路----------Polkit-Qt5 | 魔帆博客
夏叶随风 · 2017-05-26 · via 夏叶随风 – 魔帆博客

没看上一篇的需要看上一篇 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