Skip to content

Commit

Permalink
#2303 modifying os.environ is not thread safe
Browse files Browse the repository at this point in the history
so use an extra function argument instead
  • Loading branch information
totaam committed Jan 24, 2024
1 parent ea1eb43 commit 28adf9b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 6 additions & 3 deletions xpra/net/ssh/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,18 @@ def clean_agent_socket(uuid: str = "") -> None:
log.estr(e)


def setup_proxy_ssh_socket(cmdline: Iterable[str], auth_sock: str = os.environ.get("SSH_AUTH_SOCK", "")) -> str:
def setup_proxy_ssh_socket(
cmdline: Iterable[str],
auth_sock: str = os.environ.get("SSH_AUTH_SOCK", ""),
session_dir: str = os.environ.get("XPRA_SESSION_DIR"),
) -> str:
log(f"setup_proxy_ssh_socket({cmdline}, {auth_sock!r}")
# this is the socket path that the ssh client wants us to use:
# ie: "SSH_AUTH_SOCK=/tmp/ssh-XXXX4KyFhe/agent.726992"
if not auth_sock or not os.path.exists(auth_sock) or not is_socket(auth_sock):
log(f"setup_proxy_ssh_socket invalid SSH_AUTH_SOCK={auth_sock!r}")
return ""
session_dir = os.environ.get("XPRA_SESSION_DIR")
if not session_dir or not os.path.exists(session_dir):
if not session_dir or not os.path.exists(session_dir) or not os.path.isdir(session_dir):
log(f"setup_proxy_ssh_socket invalid XPRA_SESSION_DIR={session_dir!r}")
return ""
# locate the ssh agent uuid,
Expand Down
5 changes: 2 additions & 3 deletions xpra/scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3020,9 +3020,8 @@ def run_proxy(error_cb, opts, script_file, cmdline, args, mode, defaults) -> Exi
#and we use an OSEnvContext to avoid polluting the env with it
#(we need it to use the server ssh agent path functions)
session_dir = get_session_dir("attach", opts.sessions_dir, display_name, getuid())
with OSEnvContext(XPRA_SESSION_DIR=session_dir):
#ie: "/run/user/$UID/xpra/$DISPLAY/ssh/$UUID
setup_proxy_ssh_socket(cmdline)
#ie: "/run/user/$UID/xpra/$DISPLAY/ssh/$UUID
setup_proxy_ssh_socket(cmdline, session_dir=session_dir)
except OSError:
sshlog = Logger("ssh")
sshlog.error("Error setting up client ssh agent forwarding socket", exc_info=True)
Expand Down

0 comments on commit 28adf9b

Please sign in to comment.