From e8aeefa472118461672189c45402a4900d5ce486 Mon Sep 17 00:00:00 2001 From: Philipp Simon Date: Thu, 17 Nov 2022 09:04:30 +0100 Subject: [PATCH] allow user to choose uid for external authentication --- dbus_next/auth.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dbus_next/auth.py b/dbus_next/auth.py index db91c86..a3c5c01 100644 --- a/dbus_next/auth.py +++ b/dbus_next/auth.py @@ -53,14 +53,17 @@ class AuthExternal(Authenticator): :sealso: https://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol """ - def __init__(self): + def __init__(self, uid=None): self.negotiate_unix_fd = False self.negotiating_fds = False + if uid is None: + uid = os.getuid() + self.hex_uid = str(uid).encode().hex() + def _authentication_start(self, negotiate_unix_fd=False) -> str: self.negotiate_unix_fd = negotiate_unix_fd - hex_uid = str(os.getuid()).encode().hex() - return f'AUTH EXTERNAL {hex_uid}' + return f'AUTH EXTERNAL {self.hex_uid}' def _receive_line(self, line: str): response, args = _AuthResponse.parse(line)