Skip to content

Commit

Permalink
Use AuthAnnonymous() when connecting to DBus over TCP
Browse files Browse the repository at this point in the history
DBus-next defaults to using AuthExternal() when autenticating but this only works when we are working on the same machine.

Tested on Ubuntu 21.10.
  • Loading branch information
someDude12341 committed Apr 20, 2023
1 parent ffcffc8 commit da26aba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions bleak/backends/bluezdbus/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from .characteristic import BleakGATTCharacteristicBlueZDBus
from .manager import get_global_bluez_manager
from .scanner import BleakScannerBlueZDBus
from .utils import assert_reply, get_dbus_authenticator
from .utils import assert_reply, get_dbus_authenticator, should_negotiate_unix_fd
from .version import BlueZFeatures

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -144,7 +144,7 @@ async def connect(self, dangerous_use_bleak_cache: bool = False, **kwargs) -> bo
# BlueZ quirk where notifications are automatically enabled on reconnect.
self._bus = await MessageBus(
bus_type=BusType.SYSTEM,
negotiate_unix_fd=True,
negotiate_unix_fd=should_negotiate_unix_fd(),
auth=get_dbus_authenticator(),
).connect()

Expand Down
11 changes: 10 additions & 1 deletion bleak/backends/bluezdbus/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import re

from dbus_fast.auth import AuthExternal
from dbus_fast.auth import AuthExternal, AuthAnnonymous
from dbus_fast.constants import MessageType
from dbus_fast.message import Message

Expand Down Expand Up @@ -57,5 +57,14 @@ def get_dbus_authenticator():
auth = None
if uid is not None:
auth = AuthExternal(uid=uid)

if 'tcp' in os.environ.get('DBUS_SYSTEM_BUS_ADDRESS', None):
auth=AuthAnnonymous()

return auth

def should_negotiate_unix_fd():
if 'tcp' in os.environ.get('DBUS_SYSTEM_BUS_ADDRESS', None):
return False
else:
return True

0 comments on commit da26aba

Please sign in to comment.