Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DBus SystemBus policies

Tags:

policy

dbus

I wrote a program that runs as session service through dbus.
I wanted to make it run as system service (creating a dbus.SystemBus bus name) if executed by root (uid 0).
I am trying to run for dbus.SystemBus what I currently run for dbus.SessionBus but get a policy error.
The code (python but it doesn't really matter), cleared from everything unnecessary, I run is this:

import gobject
import dbus
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop

DBusGMainLoop(set_as_default=True)
loop = gobject.MainLoop()

class dbusService(dbus.service.Object):
    def __init__(self):
        bus_name = dbus.service.BusName('org.testobj.service', bus=dbus.SystemBus())
        dbus.service.Object.__init__(self, bus_name, '/org/testobj/service')

a = dbusService()

and get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in __init__
  File "/usr/lib/python2.7/site-packages/dbus/service.py", line 131, in __new__ retval = bus.request_name(name, name_flags)
  File "/usr/lib/python2.7/site-packages/dbus/bus.py", line 303, in request_name 'su', (name, flags))
  File "/usr/lib/python2.7/site-packages/dbus/connection.py", line 651, in call_blocking message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: Connection ":1.48" is not allowed to own the service "org.testobj.service" due to security policies in the configuration file
like image 311
user1476859 Avatar asked Jun 23 '12 14:06

user1476859


1 Answers

The simplest way to get going with the example above is to edit /etc/dbus-1/system.conf and add the following line:

<policy>
    ...
    <allow own="org.testobj.service"/>
</policy>

Relevant documentation.

like image 68
quiet-ranger Avatar answered Nov 07 '22 04:11

quiet-ranger