Peter Hutterer 77cc640
From a02009f81a8ee019b0642716eb68475c75eca5ec Mon Sep 17 00:00:00 2001
4edb4ea
From: Adam Jackson <ajax@redhat.com>
4edb4ea
Date: Mon, 10 Dec 2007 11:26:57 -0500
Peter Hutterer 77cc640
Subject: [PATCH] Hack for proper MIT-SHM rejection for ssh-forwarded clients.
4edb4ea
4edb4ea
---
c22de5d
 Xext/shm.c |   16 ++++++++++++++++
c22de5d
 1 files changed, 16 insertions(+), 0 deletions(-)
4edb4ea
4edb4ea
diff --git a/Xext/shm.c b/Xext/shm.c
Peter Hutterer 77cc640
index 23afe6b..1e2f9f5 100644
4edb4ea
--- a/Xext/shm.c
4edb4ea
+++ b/Xext/shm.c
Peter Hutterer 77cc640
@@ -325,8 +325,21 @@ shm_access(ClientPtr client, SHMPERM_TYPE *perm, int readonly)
4edb4ea
     mode_t mask;
4edb4ea
     int uidset = 0, gidset = 0;
4edb4ea
     LocalClientCredRec *lcc;
4edb4ea
+    Bool is_ssh = FALSE;
4edb4ea
     
4edb4ea
     if (GetLocalClientCreds(client, &lcc) != -1) {
4edb4ea
+#ifdef linux
4edb4ea
+	if (lcc->fieldsSet & LCC_PID_SET) {
4edb4ea
+	    /* ssh isn't actually a local client */
4edb4ea
+	    char exe[64], buf[64];
4edb4ea
+
73fc924
+	    memset(buf, 0, 64);
4edb4ea
+	    snprintf(exe, 64, "/proc/%d/exe", lcc->pid);
73fc924
+	    readlink(exe, buf, 63);
4edb4ea
+	    if (strstr(buf, "/ssh"))
4edb4ea
+		is_ssh = TRUE;
4edb4ea
+	}
4edb4ea
+#endif
4edb4ea
 
4edb4ea
 	if (lcc->fieldsSet & LCC_UID_SET) {
4edb4ea
 	    uid = lcc->euid;
Peter Hutterer 77cc640
@@ -345,6 +358,9 @@ shm_access(ClientPtr client, SHMPERM_TYPE *perm, int readonly)
4edb4ea
 	}
4edb4ea
 #endif
4edb4ea
 	FreeLocalClientCreds(lcc);
4edb4ea
+
4edb4ea
+	if (is_ssh)
4edb4ea
+	    return -1;
4edb4ea
 	
4edb4ea
 	if (uidset) {
4edb4ea
 	    /* User id 0 always gets access */
4edb4ea
-- 
Peter Hutterer 77cc640
1.7.3.2
4edb4ea