linux - 系统 D-Bus 不允许使用 conf 文件取消所有权

标签 linux configuration dbus qtdbus

我正在尝试创建一个在系统总线上运行的守护进程服务,该服务的发送和接收权限应该对任何人完全开放。 (安全不是此服务的问题)。当我尝试使用 QtDbus(为此使用 PyQt)注册服务时,出现此错误:Connection ":1.0"is not allowed to own the service "org.dbus.arduino"due to security policies in the configuration文件。 This other stack overflow 有同样的错误,但由于某种原因在这种情况下根本没有帮助。 dbus_bus_request_name (): Connections are not allowed to own the service .

通常您应该保留 system.conf 文件并在 system.d 目录中添加您的权限“punch out”配置文件。我已经这样做了,但它似乎没有改变任何东西,无论我如何开放权限。事实上,我几乎可以肯定它没有改变任何东西!这是我现在的 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>  

我什至将文件名以 z 开头,这样它可能是最后读入的文件。这是 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,也没有 session 总线)。只有完全允许系统总线上的所有内容,我才能让 Raspberry Pi 工作(在这个设备上,安全性几乎不是什么大问题)。显然,我决不允许这种情况发生在我的开发机器上。作为背景,我使用的是 Opensuse 12.2,Raspberry Pi 是 Debian Squeeze。我无法使用我的用户帐户或 root 拥有该服务,除非我完全打开权限,在这种情况下它工作得很好。我还会注意到,当我完全打开系统总线时,我仍然必须使用 root 向守护进程发送消息(终止命令)。我希望该解决方案能够通过具有 root 访问权限的特定用户运行。我也同意只允许同一用户和 root 向其发送消息的解决方案。

感谢您的帮助,我确定这是一个小问题!

最佳答案

我终于找到问题了。当 Dbus 查找配置文件以获取权限(如所有权)时,该文件不仅必须位于 system.d/中,而且还必须以 .conf 结尾。

我的配置文件“org.dbus.arduino”应该是“org.dbus.arduino.conf”。我从 system.conf 中删除了代码。确认我不再有权限,在“system.d/org.dbus.arduino.conf”创建了一个配置文件,我被授予了权限。然后我尝试将文件重命名为“org.dbus.arduino”并确认权限被拒绝。

关于linux - 系统 D-Bus 不允许使用 conf 文件取消所有权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23156941/

相关文章:

macos - 在 ubuntu 机器中导入在 mac 上创建的 neo4j db 失败 - ubuntu 上的 neo4j.conf 与 mac 不同吗?

c - 如何解析 "a(oa{sv})"dbus类型?

linux - 连接到 Windows Azure 的 Ftp 命令语法

linux - readelf 不显示共享库的版本号

javascript - Linux 上的 Node.js 依赖项不兼容

python - 溢出错误 : user id is too big

configuration - 是否可以更改 Mercurial 中的默认 diff 工具?

java - 在 Spring 配置文件中定义变量以访问包含图像的外部文件夹

perl - 如何以 root 身份运行 Perl 脚本但仍然影响用户 gconf 设置

c - DBus Glib 发送信号 - 没有发出信号