4edb4e
From 4306b434038de7e2b17d3c4a6cfd87db469d3bda Mon Sep 17 00:00:00 2001
4edb4e
From: Adam Jackson <ajax@redhat.com>
4edb4e
Date: Mon, 10 Dec 2007 11:26:57 -0500
4edb4e
Subject: [PATCH] Hack for proper MIT-SHM rejection for ssh-forwarded clients.
4edb4e
4edb4e
---
4edb4e
 Xext/shm.c |   15 +++++++++++++++
4edb4e
 1 files changed, 15 insertions(+), 0 deletions(-)
4edb4e
4edb4e
diff --git a/Xext/shm.c b/Xext/shm.c
4edb4e
index 5937a03..5376c19 100644
4edb4e
--- a/Xext/shm.c
4edb4e
+++ b/Xext/shm.c
73fc92
@@ -381,8 +381,21 @@
4edb4e
     mode_t mask;
4edb4e
     int uidset = 0, gidset = 0;
4edb4e
     LocalClientCredRec *lcc;
4edb4e
+    Bool is_ssh = FALSE;
4edb4e
     
4edb4e
     if (GetLocalClientCreds(client, &lcc) != -1) {
4edb4e
+#ifdef linux
4edb4e
+	if (lcc->fieldsSet & LCC_PID_SET) {
4edb4e
+	    /* ssh isn't actually a local client */
4edb4e
+	    char exe[64], buf[64];
4edb4e
+
73fc92
+	    memset(buf, 0, 64);
4edb4e
+	    snprintf(exe, 64, "/proc/%d/exe", lcc->pid);
73fc92
+	    readlink(exe, buf, 63);
4edb4e
+	    if (strstr(buf, "/ssh"))
4edb4e
+		is_ssh = TRUE;
4edb4e
+	}
4edb4e
+#endif
4edb4e
 
4edb4e
 	if (lcc->fieldsSet & LCC_UID_SET) {
4edb4e
 	    uid = lcc->euid;
73fc92
@@ -401,6 +414,9 @@
4edb4e
 	}
4edb4e
 #endif
4edb4e
 	FreeLocalClientCreds(lcc);
4edb4e
+
4edb4e
+	if (is_ssh)
4edb4e
+	    return -1;
4edb4e
 	
4edb4e
 	if (uidset) {
4edb4e
 	    /* User id 0 always gets access */
4edb4e
-- 
4edb4e
1.5.3.4
4edb4e