Jay*_*Jay 10 linux gnome-shell gnome-3 gnome-shell-extensions
我正在构建一个Gnome shell扩展,我希望能够使用升级的权限做一些事情.所以,我想我需要使用"政策工具包",但我不知道如何去做这件事.
所以,说我想做点什么ifconfig eth0 down
或者做什么ifconfig eth0 up
我可以从终端运行:pkexec ifconfig eth0 down
它会提示输入密码然后再进行操作.
但是,我应该如何从扩展内部做到这一点?
我很确定它与在/ usr/share/polkit-1/actions中创建文件有关,但我在互联网上找不到任何东西.
我希望能够设置它,以便不需要输入密码,扩展只需运行某个命令.
我知道允许任何命令运行是一个非常糟糕的主意.这不是我要求的,我希望能够只运行一个程序/命令.
编辑:我不确定,但我认为没有必要输入密码可能是不可能的.我只是知道sudo第一次没有问一段时间的密码,所以我想要类似的功能.不确定有什么可能.
我已经很长时间没有使用PolicyKit了,但据我记得,你确实需要在actions/目录中创建一个文件,其内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<policyconfig>
<action id="org.freedesktop.policykit.pkexec.run-ifconfig">
<description>Configure network</description>
<message>Authentication is required to set ifconfig parameters</message>
<defaults>
<allow_any>no</allow_any>
<allow_inactive>no</allow_inactive>
<allow_active>...</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/sbin/ifconfig</annotate>
</action>
</policyconfig>
Run Code Online (Sandbox Code Playgroud)
您必须更改以下值:
<allow_active>...</allow_active>
Run Code Online (Sandbox Code Playgroud)
到你想要的值。选择 的值:
将allow_active 密钥的值更改为“yes”应该会停止身份验证要求。
然后您需要根据您的需要调整操作文件并调用它。
雨果,