Skip to content

Commit

Permalink
Add support for EXTERNAL auth without uid
Browse files Browse the repository at this point in the history
  • Loading branch information
mvn23 committed Jan 4, 2023
1 parent 4c9a8fe commit e3f1bd9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/dbus_fast/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def __init__(self, uid: int = None) -> None:
def _authentication_start(self, negotiate_unix_fd: bool = False) -> str:
self.negotiate_unix_fd = negotiate_unix_fd
uid = self.uid
if uid == -1:
return "AUTH EXTERNAL"
if uid is None:
uid = os.getuid()
hex_uid = str(uid).encode().hex()
Expand All @@ -86,6 +88,9 @@ def _receive_line(self, line: str) -> str:
if response is _AuthResponse.AGREE_UNIX_FD:
return "BEGIN"

if response is _AuthResponse.DATA and self.uid == -1:
return _AuthResponse.DATA

raise AuthError(f"authentication failed: {response.value}: {args}")


Expand Down
5 changes: 5 additions & 0 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@
def test_uid_is_set():
auth = AuthExternal(uid=999)
assert auth._authentication_start() == "AUTH EXTERNAL 393939"


def test_no_uid():
auth = AuthExternal(uid=-1)
assert auth._authentication_start() == "AUTH EXTERNAL"

0 comments on commit e3f1bd9

Please sign in to comment.