Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use AuthAnnonymous() when connecting to DBus over TCP #796

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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