22def main() -> int:
23 if len(sys.argv) != 2:
24 print(f"usage: {sys.argv[0]} <url>", file=sys.stderr)
25 return 1
26
27 url = sys.argv[1]
28 parsed = urllib.parse.urlparse(url)
29
30
31
32
33
34 if parsed.netloc.lower() == "microsoft.aad.brokerplugin":
35 state_values = urllib.parse.parse_qs(parsed.query).get("state")
36 if not state_values:
37 print(f"no state parameter found in {url!r}", file=sys.stderr)
38 return 1
39
40 freerdp_id = state_values[0].split(".", 1)[0]
41 runtime_dir = os.environ.get("XDG_RUNTIME_DIR", "/tmp")
42 sock_path = os.path.join(runtime_dir, f"freerdp_aad_{freerdp_id}.sock")
43
44 try:
45 with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
46 sock.connect(sock_path)
47 sock.sendall(url.encode() + b"\n")
48 except OSError as exc:
49 print(f"could not reach {sock_path}: {exc}", file=sys.stderr)
50 return 1
51
52 return 0
53
54