summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorS. Gilles <sgilles@math.umd.edu>2019-06-03 10:16:02 -0400
committerOri Bernstein <ori@eigenstate.org>2019-08-20 19:58:23 -0700
commit5c30b238adad48bae21c3ac3a1a22d1707cc7b80 (patch)
tree74f388739ae5a9e4d0cab753543b7287c17d6bea
parent73de0178245ecf1b64ef5135483f021b0143dd1c (diff)
downloadlibxmyrb-5c30b238adad48bae21c3ac3a1a22d1707cc7b80.tar.gz
Check auth addr before connectingHEADmaster
It is possible for .Xauthority to contain multiple authorizations for the same machine, and for the correct authorization to not be the first. For example, this may be true on Linux machines if the hostname of the machine has changed since boot (even if that change was before the X server was started).
-rw-r--r--display.myr19
1 files changed, 19 insertions, 0 deletions
diff --git a/display.myr b/display.myr
index 70d99d4..d82c13f 100644
--- a/display.myr
+++ b/display.myr
@@ -1,6 +1,7 @@
use std
use iter
use fileutil
+use sys
use "xproto-gen"
use "types"
@@ -146,6 +147,7 @@ const handshake = {dpy
var req : byte[512]
var auth, zauth, valid, sz
var buf, setup
+ var rightaddr
zauth = [
.family=0,
@@ -155,11 +157,15 @@ const handshake = {dpy
.data=""
]
auth = &zauth
+ rightaddr = getrightaddr(dpy)
for a : iter.byref(dpy.auth)
match std.intparse(a.num)
| `std.None: /* skip */
| `std.Some n:
valid = false
+ if a.family != AuthfamWild && !std.sleq(a.addr, rightaddr)
+ continue
+ ;;
match a.family
| AuthfamWild: valid = true
| AuthfamLocal: valid = std.sleq(dpy.host, "")
@@ -173,6 +179,7 @@ const handshake = {dpy
;;
;;
;;
+ std.slfree(rightaddr)
/*
packed by hand because our donemsg function overwrites the assumed
@@ -237,6 +244,18 @@ const handshake = {dpy
-> `std.Ok setup
}
+const getrightaddr = {dpy
+ if dpy.host.len > 0
+ -> std.sldup(dpy.host)
+ ;;
+
+ var u : sys.utsname
+ sys.uname(&u)
+ match std.strfind(u.node[:], "\0")
+ | `std.Some l: -> std.sldup(u.node[:l])
+ | `std.None: -> std.sldup(u.node[:])
+ ;;
+}
const parsemagic = {path -> auth[:]
var data, buf, auth, ret