Dbus服务以root身份启动,其他用户无法访问



我有一个dbus服务器发布一些以root启动的方法。

当我尝试使用一个小型python客户端访问它时,我无法访问它,直到我以root身份启动客户端。

如何以系统用户访问以root启动的D-Bus服务

我问这个问题是因为缺乏D-Bus的经验和知识。

在我的例子中,我使用SessionBus来发布我的方法。顾名思义,它是一个与会话相关的总线。基本上,如果我用我的会话(我的用户)启动D-Bus服务,那么我的用户就可以访问它。

在我的情况下,我需要的是使用SystemBus。

来自文档(http://dbus.freedesktop.org/doc/dbus-specification.html#introduction):

)

D-Bus是为两个特定的用例设计的:

  • 一个"系统总线",用于从系统到用户会话的通知,并允许系统从用户会话请求输入。

  • 用于实现GNOME和KDE等桌面环境的"会话总线"。

我有同样的问题。我正在与/etc/dbus-1/system中的.conf文件作斗争。但是文档是我读过的最糟糕的东西。http://dbus.freedesktop.org/doc/dbus-daemon.1.html

我认为你的问题可以通过配置你的总线来解决。现在我有这个配置文件:
    <policy context="default">
            <allow send_interface="org.company.mybus"/>
            <allow receive_interface="org.company.mybus"
                   receive_sender="org.company.mybus"/>
    </policy>

这样我就可以实例化总线,但是当我调用导出的方法initial_sync_data时,出现异常:

dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: 
    Rejected send message, 3 matched rules; type="method_call", sender=":1.254"     (uid=100108 pid=5632 comm="python applet_quota.py ") interface="(unset)" member="initial_sync_data" error name="(unset)" requested_reply="0" destination=":1.253" (uid=0 pid=5603 comm="python main.py ")

相关内容

最新更新