Skip to content

Commit bfcb1fd

Browse files
committed
Use AuthAnnonymous() when connecting to DBus over TCP
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.
1 parent eddd1e1 commit bfcb1fd

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

bleak/backends/bluezdbus/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from .characteristic import BleakGATTCharacteristicBlueZDBus
3131
from .manager import get_global_bluez_manager
3232
from .scanner import BleakScannerBlueZDBus
33-
from .utils import assert_reply, get_dbus_authenticator
33+
from .utils import assert_reply, get_dbus_authenticator, should_negotiate_unix_fd
3434
from .version import BlueZFeatures
3535

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

bleak/backends/bluezdbus/utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import re
44

5-
from dbus_fast.auth import AuthExternal
5+
from dbus_fast.auth import AuthExternal, AuthAnnonymous
66
from dbus_fast.constants import MessageType
77
from dbus_fast.message import Message
88

@@ -57,5 +57,14 @@ def get_dbus_authenticator():
5757
auth = None
5858
if uid is not None:
5959
auth = AuthExternal(uid=uid)
60+
61+
if 'tcp' in os.environ.get('DBUS_SYSTEM_BUS_ADDRESS', None):
62+
auth=AuthAnnonymous()
6063

6164
return auth
65+
66+
def should_negotiate_unix_fd():
67+
if 'tcp' in os.environ.get('DBUS_SYSTEM_BUS_ADDRESS', None):
68+
return False
69+
else:
70+
return True

0 commit comments

Comments
 (0)