我正在尝试创建一个在系统总线上运行的守护程序服务,其中从该服务发送和接收的权限应该对任何人完全开放。(安全性不是此服务的问题)。当我尝试使用 QtDbus 注册服务时(使用 PyQt),我收到此错误:Connection ":1.0" is not allowed to own the service "org.dbus.arduino" due to security policies in the configuration file
. 另一个堆栈溢出具有相同的错误,但由于某种原因在这种情况下根本没有帮助。dbus_bus_request_name ()
: 不允许连接拥有服务。
通常,您应该保留该system.conf
文件并在目录中添加您的权限“打孔”配置文件system.d
。我已经这样做了,但它似乎并没有改变任何东西,无论我如何打开权限。事实上,我几乎可以肯定它不会改变任何东西!这是我的 conf 文件,因为它就在此刻。
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<policy user="myUser">
<allow own="*"/>
<allow own="org.dbus.arduino"/>
<allow send_type="method_call" log="true"/>
</policy>
<policy user="root">
<allow own="*"/>
<allow own="org.dbus.arduino"/>
<allow send_type="method_call" log="true"/>
</policy>
<policy context="default">
</policy>
</busconfig>
即使我这样做或类似的事情,它仍然不起作用。
<busconfig>
<policy context="default">
<allow own="*"/>
<allow own="org.dbus.arduino"/>
<allow send_type="method_call" log="true"/>
</policy>
</busconfig>
我什至将文件的名称以 az 开头,以便它可能是最后一个被读入的文件。这是 system.conf 文件,注意我在哪里注释掉了“允许自己”部分。这是让它工作的唯一方法(也是最糟糕的“修复”)。
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<!-- Our well-known bus type, do not change this -->
<type>system</type>
<!-- Run as special user -->
<user>messagebus</user>
<!-- Fork into daemon mode -->
<fork/>
<!-- We use system service launching using a helper -->
<standard_system_servicedirs/>
<!-- This is a setuid helper that is used to launch system services -->
<servicehelper>/lib/dbus-1/dbus-daemon-launch-helper</servicehelper>
<!-- Write a pid file -->
<pidfile>/var/run/dbus/pid</pidfile>
<!-- Enable logging to syslog -->
<syslog/>
<!-- Only allow socket-credentials-based authentication -->
<auth>EXTERNAL</auth>
<!-- Only listen on a local socket. (abstract=/path/to/socket
means use abstract namespace, don't really create filesystem
file; only Linux supports this. Use path=/whatever on other
systems.) -->
<listen>unix:path=/var/run/dbus/system_bus_socket</listen>
<policy context="default">
<!-- All users can connect to system bus -->
<allow user="*"/>
<!-- Holes must be punched in service configuration files for
name ownership and sending method calls -->
<deny own="*"/>
<deny send_type="method_call" log="true"/>
<!-- THIS IS THE ONLY WAY TO GET THIS TO WORK
<allow own="*"/>
<allow send_type="method_call" log="true"/>
-->
<!-- Signals and reply messages (method returns, errors) are allowed
by default -->
<allow send_type="signal"/>
<allow send_requested_reply="true" send_type="method_return"/>
<allow send_requested_reply="true" send_type="error"/>
<!-- All messages may be received by default -->
<allow receive_type="method_call"/>
<allow receive_type="method_return"/>
<allow receive_type="error"/>
<allow receive_type="signal"/>
<!-- Allow anyone to talk to the message bus -->
<allow send_destination="org.freedesktop.DBus"/>
<!-- But disallow some specific bus services -->
<deny send_destination="org.freedesktop.DBus"
send_interface="org.freedesktop.DBus"
send_member="UpdateActivationEnvironment"/>
</policy>
<!-- Config files are placed here that among other things, punch
holes in the above policy for specific services. -->
<includedir>system.d</includedir>
<!-- This is included last so local configuration can override what's
in this standard file -->
<include ignore_missing="yes">system-local.conf</include>
<include if_selinux_enabled="yes" selinux_root_relative="yes">contexts/dbus_contexts</include>
</busconfig>
我绝对必须使用系统总线,因为我将它部署在没有 GUI 的 Raspberry Pi 上(没有 x11,也没有会话总线)。只有完全允许系统总线上的所有内容,我才能让 Raspberry Pi 正常工作(在这个设备上,安全性并没有那么重要)。显然,我不允许在我的开发机器上发生这种情况。作为背景,我使用的是 Opensuse 12.2,而 Raspberry Pi 是 Debian Squeeze。除非我完全打开权限,否则我不能用我的用户帐户或 root 拥有该服务,在这种情况下它工作得很好。我还要注意,当我完全打开系统总线时,我仍然必须使用 root 向守护进程发送消息(终止命令)。我希望该解决方案能够通过具有 root 访问权限的特定用户运行。
感谢您的帮助,我确定这是一个小问题!