xpra icon
Bug tracker and wiki

Ticket #1640: dbus-proxy-server.patch

File dbus-proxy-server.patch, 11.7 KB (added by Antoine Martin, 3 years ago)

work in progress - only selinux to fix

  • ../rpmbuild/xpra.spec

     
    573573%{_datadir}/mime/packages/application-x-xpraconfig.xml
    574574
    575575%files common-server
     576%{_sysconfdir}/dbus-1/system.d/xpra.conf
    576577%{_bindir}/udev_product_version
    577578%{_prefix}/lib/systemd/system/xpra.service
    578579%{_prefix}/lib/systemd/system/xpra.socket
     
    729730fi
    730731udevadm control --reload-rules && udevadm trigger || :
    731732%endif
     733#reload dbus to get our new policy:
     734sudo systemctl reload dbus
    732735
    733736%post common-client
    734737/usr/bin/update-mime-database &> /dev/null || :
  • xpra/server/dbus/dbus_server.py

     
    77from collections import namedtuple
    88from xpra.dbus.helper import dbus_to_native, native_to_dbus
    99from xpra.dbus.common import init_session_bus
     10from xpra.server.dbus.dbus_server_base import DBUS_Server_Base, INTERFACE, BUS_NAME
    1011from xpra.util import parse_scaling_value, from0to100
    1112import dbus.service
    1213
     
    1314from xpra.log import Logger, add_debug_category, remove_debug_category, disable_debug_for, enable_debug_for
    1415log = Logger("dbus", "server")
    1516
    16 BUS_NAME = "org.xpra.Server"
    17 INTERFACE = "org.xpra.Server"
    18 PATH = "/org/xpra/Server"
    1917
    2018Rectangle = namedtuple("Workarea", "x,y,width,height")
    2119
     
    3432    return int(v*1000.0)
    3533
    3634
    37 class DBUS_Server(dbus.service.Object):
     35class DBUS_Server(DBUS_Server_Base):
    3836
    3937    def __init__(self, server=None, extra=""):
    40         self.server = server
    41         session_bus = init_session_bus()
     38        bus = init_session_bus()
    4239        name = BUS_NAME
    43         path = PATH
    4440        if extra:
    4541            name += extra.replace(".", "_").replace(":", "_")
    46         bus_name = dbus.service.BusName(name, session_bus)
    47         dbus.service.Object.__init__(self, bus_name, path)
    48         self.log("(%s)", server)
    49         self._properties = {
    50                             "idle-timeout"          : ("idle_timeout",          ni),
    51                             "server-idle-timeout"   : ("server_idle_timeout",   ni),
    52                             "name"                  : ("session_name",          ns),
    53                             "sharing"               : ("sharing",               nb),
    54                             }
     42        DBUS_Server_Base.__init__(self, bus, server, name)
     43        self._properties.update({
     44            "idle-timeout"          : ("idle_timeout",          ni),
     45            "server-idle-timeout"   : ("server_idle_timeout",   ni),
     46            "name"                  : ("session_name",          ns),
     47            "sharing"               : ("sharing",               nb),
     48            })
    5549
    56     def cleanup(self):
    57         try:
    58             log("calling %s", self.remove_from_connection)
    59             self.remove_from_connection()
    60         except Exception as e:
    61             log.error("Error removing the DBUS server:")
    62             log.error(" %s", e)
    6350
    64 
    65     def log(self, fmt, *args):
    66         log("%s"+fmt, INTERFACE, *args)
    67 
    68 
    69     @dbus.service.signal(INTERFACE, signature='sas')
    70     def Event(self, event, args):
    71         self.log(".Event(%s, %s)", event, args);
    72 
    73 
    74     @dbus.service.method(dbus.PROPERTIES_IFACE, in_signature='s', out_signature='v')
    75     def Get(self, property_name):
    76         conv = self._properties.get(property_name)
    77         if conv is None:
    78             raise dbus.exceptions.DBusException("invalid property")
    79         server_property_name, _ = conv
    80         v = getattr(self.server, server_property_name)
    81         self.log(".Get(%s)=%s", property_name, v)
    82         return v
    83 
    84     @dbus.service.method(dbus.PROPERTIES_IFACE, in_signature='', out_signature='a{sv}')
    85     def GetAll(self, interface_name):
    86         if interface_name==INTERFACE:
    87             v = dict((x, self.Get(x)) for x in self._properties.keys())
    88         else:
    89             v = {}
    90         self.log(".GetAll(%s)=%s", interface_name, v)
    91         return v
    92 
    93     @dbus.service.method(dbus.PROPERTIES_IFACE, in_signature='ssv')
    94     def Set(self, interface_name, property_name, new_value):
    95         self.log(".Set(%s, %s, %s)", interface_name, property_name, new_value)
    96         conv = self._properties.get(property_name)
    97         if conv is None:
    98             raise dbus.exceptions.DBusException("invalid property")
    99         server_property_name, validator = conv
    100         assert hasattr(self.server, server_property_name)
    101         setattr(self.server, server_property_name, validator(new_value))
    102 
    103     @dbus.service.signal(dbus.PROPERTIES_IFACE, signature='sa{sv}as')
    104     def PropertiesChanged(self, interface_name, changed_properties, invalidated_properties):
    105         pass
    106 
    107 
    10851    @dbus.service.method(INTERFACE, in_signature='i')
    10952    def Focus(self, wid):
    11053        self.log(".Focus(%i)", wid)
  • xpra/server/proxy/proxy_server.py

     
    8181        get_platform_info()
    8282        self.child_reaper = getChildReaper()
    8383
    84     def init_components(self, opts):
    85         pass
    8684
     85    def make_dbus_server(self):
     86        from xpra.server.proxy.proxy_dbus_server import Proxy_DBUS_Server
     87        return Proxy_DBUS_Server(self)
     88
     89
    8790    def init_packet_handlers(self):
    8891        ServerCore.init_packet_handlers(self)
    8992        #add shutdown handler
     
    476479            if sessions:
    477480                uid, gid = sessions[:2]
    478481                if not POSIX or (uid==os.getuid() and gid==os.getgid()):
    479                     info.update(ServerCore.get_info(self, proto))
    480482                    self.reap()
    481483                    i = 0
    482484                    for p,v in self.processes.items():
  • xpra/server/server_base.py

     
    115115        self.clipboard_direction = "both"
    116116        self.supports_dbus_proxy = False
    117117        self.dbus_helper = None
    118         self.dbus_control = False
    119         self.dbus_server = None
    120118        self.lpadmin = ""
    121119        self.lpinfo = ""
    122120        self.add_printer_options = []
     
    256254        self.lpinfo = opts.lpinfo
    257255        self.add_printer_options = opts.add_printer_options
    258256        self.av_sync = opts.av_sync
    259         self.dbus_control = opts.dbus_control
    260257        #server-side printer handling is only for posix via pycups for now:
    261258        self.postscript_printer = opts.postscript_printer
    262259        self.pdf_printer = opts.pdf_printer
     
    278275
    279276    def init_components(self, opts):
    280277        log("starting component init")
     278        ServerCore.init_components(self, opts)
    281279        self.init_webcam()
    282280        self.init_clipboard()
    283281        self.init_keyboard()
     
    285283        self.init_sound_options(opts)
    286284        self.init_notification_forwarder()
    287285        self.init_dbus_helper()
    288         self.init_dbus_server()
    289286
    290287        if opts.system_tray:
    291288            self.add_system_tray()
     
    695692            self.dbus_helper = None
    696693            self.supports_dbus_proxy = False
    697694
    698     def init_dbus_server(self):
    699         dbuslog("init_dbus_server() dbus_control=%s", self.dbus_control)
    700         if not self.dbus_control:
    701             return
    702         try:
    703             from xpra.server.dbus.dbus_common import dbus_exception_wrap
    704             self.dbus_server = dbus_exception_wrap(self.make_dbus_server, "setting up server dbus instance")
    705         except Exception as e:
    706             log("init_dbus_server()", exc_info=True)
    707             log.error("Error: cannot load dbus server:")
    708             log.error(" %s", e)
    709             self.dbus_server = None
    710695
    711 
    712696    def make_dbus_server(self):
    713697        from xpra.server.dbus.dbus_server import DBUS_Server
    714698        return DBUS_Server(self, os.environ.get("DISPLAY", "").lstrip(":"))
     
    990974        reaper_cleanup()
    991975        self.cleanup_pulseaudio()
    992976        self.stop_virtual_webcam()
    993         ds = self.dbus_server
    994         if ds:
    995             ds.cleanup()
    996             self.dbus_server = None
    997977
    998978
    999979    def _process_exit_server(self, _proto, _packet):
  • xpra/server/server_core.py

     
    2424commandlog = Logger("command")
    2525authlog = Logger("auth")
    2626timeoutlog = Logger("timeout")
     27dbuslog = Logger("dbus")
    2728
    2829from xpra.version_util import XPRA_VERSION
    2930from xpra.scripts.main import _socket_connect, full_version_str
     
    169170        self._socket_timeout = SERVER_SOCKET_TIMEOUT
    170171        self._ws_timeout = 5
    171172        self._socket_dir = None
     173        self.dbus_control = False
     174        self.dbus_server = None
    172175        self.unix_socket_paths = []
    173176
    174177        self.session_name = ""
     
    218221        self.server_idle_timeout = opts.server_idle_timeout
    219222        self.readonly = opts.readonly
    220223        self.ssl_mode = opts.ssl
     224        self.dbus_control = opts.dbus_control
    221225
     226    def init_components(self, opts):
    222227        self.init_html_proxy(opts)
    223228        self.init_auth(opts)
     229        self.init_dbus_server()
    224230
    225231
     232    def init_dbus_server(self):
     233        dbuslog("init_dbus_server() dbus_control=%s", self.dbus_control)
     234        if not self.dbus_control:
     235            return
     236        try:
     237            from xpra.server.dbus.dbus_common import dbus_exception_wrap
     238            self.dbus_server = dbus_exception_wrap(self.make_dbus_server, "setting up server dbus instance")
     239        except Exception as e:
     240            log("init_dbus_server()", exc_info=True)
     241            log.error("Error: cannot load dbus server:")
     242            log.error(" %s", e)
     243            self.dbus_server = None
     244
     245    def cleanup_dbus_server(self):
     246        ds = self.dbus_server
     247        if ds:
     248            ds.cleanup()
     249            self.dbus_server = None
     250
     251
     252    def make_dbus_server(self):
     253        dbuslog("make_dbus_server() no dbus server for %s", self)
     254        return None
     255
     256
    226257    def init_uuid(self):
    227258        # Define a server UUID if needed:
    228259        self.uuid = self.get_uuid()
     
    537568        self.cleanup_protocols(protocols, reason, True)
    538569        self._potential_protocols = []
    539570        self.cleanup_udp_listeners()
     571        self.cleanup_dbus_server()
    540572
    541573    def do_cleanup(self):
    542574        #allow just a bit of time for the protocol packet flush
  • dbus/xpra.conf

     
     1<!DOCTYPE busconfig PUBLIC
     2          "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
     3          "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
     4<busconfig>
     5
     6  <!-- Only root can own the xpra service -->
     7  <policy user="root">
     8    <allow own="org.xpra.Server"/>
     9  </policy>
     10
     11  <!-- Allow anyone to invoke methods on xpra server -->
     12  <policy context="default">
     13    <allow send_destination="org.xpra.Server"/>
     14    <allow receive_sender="org.xpra.Server"/>
     15  </policy>
     16</busconfig>
  • setup.py

     
    15181518                    copytodir("etc/sysconfig/xpra", "/etc/default")
    15191519            if sd_listen_ENABLED:
    15201520                copytodir("service/xpra.socket", systemd_dir)
     1521            if dbus_ENABLED and proxy_ENABLED:
     1522                copytodir("dbus/xpra.conf", "/etc/dbus-1/system.d")
    15211523
    15221524
    15231525    # add build_conf to build step