Skip to content

Commit

Permalink
initialize the challenge handlers later
Browse files Browse the repository at this point in the history
so they can have access to more data, ie: connection, display attributes, etc
  • Loading branch information
totaam committed Feb 7, 2025
1 parent b728ce2 commit 4f7cc83
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
19 changes: 11 additions & 8 deletions xpra/client/base/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def defaults_init(self) -> None:
self.hello_extra = {}
self.compression_level = 0
self.display = None
self.challenge_handlers_option = ()
self.challenge_handlers = []
self.username = None
self.password = None
Expand Down Expand Up @@ -164,7 +165,7 @@ def init(self, opts) -> None:
self.password_file = opts.password_file
self.encryption = opts.encryption or opts.tcp_encryption
self.encryption_keyfile = opts.encryption_keyfile or opts.tcp_encryption_keyfile
self.init_challenge_handlers(opts.challenge_handlers)
self.challenge_handlers_option = opts.challenge_handlers
self.install_signal_handlers()

def show_progress(self, pct: int, text="") -> None:
Expand All @@ -175,10 +176,10 @@ def show_progress(self, pct: int, text="") -> None:
if pp:
pp.progress(pct, text)

def init_challenge_handlers(self, challenge_handlers) -> None:
def init_challenge_handlers(self) -> None:
# register the authentication challenge handlers:
authlog(f"init_challenge_handlers({challenge_handlers})")
ch = tuple(x.strip() for x in (challenge_handlers or ()))
authlog("init_challenge_handlers() %r", self.challenge_handlers_option)
ch = tuple(x.strip() for x in (self.challenge_handlers_option or ()))
for ch_name in ch:
if ch_name == "none":
continue
Expand All @@ -192,9 +193,7 @@ def init_challenge_handlers(self, challenge_handlers) -> None:
instance = self.get_challenge_handler(auth, ierror)
if instance:
self.challenge_handlers.append(instance)
if DETECT_LEAKS:
print_leaks = detect_leaks()
GLib.timeout_add(10 * 1000, print_leaks)
authlog("challenge-handlers=%r", self.challenge_handlers)

def get_challenge_handler(self, auth: str, import_error_logger: Callable):
# the module may have attributes,
Expand All @@ -205,6 +204,7 @@ def get_challenge_handler(self, auth: str, import_error_logger: Callable):
if len(parts) == 2:
kwargs = parse_simple_dict(parts[1])
kwargs["protocol"] = self._protocol
kwargs["display-desc"] = self.display_desc
if "password" not in kwargs and self.password:
kwargs["password"] = self.password
if self.password_file:
Expand Down Expand Up @@ -373,7 +373,7 @@ def make_protocol(self, conn):
return protocol

def setup_connection(self, conn) -> None:
pass
self.init_challenge_handlers()

def has_password(self) -> bool:
return self.password or self.password_file or os.environ.get('XPRA_PASSWORD')
Expand Down Expand Up @@ -657,6 +657,9 @@ def glib_init() -> None:
register_SIGUSR_signals(GLib.idle_add)

def run(self) -> ExitValue:
if DETECT_LEAKS:
print_leaks = detect_leaks()
GLib.timeout_add(10 * 1000, print_leaks)
self.start_protocol()
return 0

Expand Down
3 changes: 1 addition & 2 deletions xpra/client/mixins/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,11 @@ def init(self, opts) -> None:
self.overlay_image = Image.open(icon_filename)
traylog("overlay_image=%s", self.overlay_image)

def setup_connection(self, conn):
def setup_connection(self, conn) -> None:
display_name = getattr(self, "display_desc", {}).get("display_name", "")
if display_name:
# now that we have display_desc, parse the border again:
self.border = parse_border(self.border_str, display_name)
return conn

def run(self) -> ExitValue:
# we decode pixel data in this thread
Expand Down

0 comments on commit 4f7cc83

Please sign in to comment.