Blob Blame History Raw
From b7979b8521272d53531ffd1cf3566ce4e5c0469b Mon Sep 17 00:00:00 2001
From: Adam Jackson <ajax@redhat.com>
Date: Mon, 10 Dec 2007 11:26:57 -0500
Subject: [PATCH 04/17] Hack for proper MIT-SHM rejection for ssh-forwarded clients.

---
 Xext/shm.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/Xext/shm.c b/Xext/shm.c
index 3230d83..7f0ad91 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -389,8 +389,21 @@ shm_access(ClientPtr client, SHMPERM_TYPE *perm, int readonly)
     mode_t mask;
     int uidset = 0, gidset = 0;
     LocalClientCredRec *lcc;
+    Bool is_ssh = FALSE;
     
     if (GetLocalClientCreds(client, &lcc) != -1) {
+#ifdef linux
+	if (lcc->fieldsSet & LCC_PID_SET) {
+	    /* ssh isn't actually a local client */
+	    char exe[64], buf[64];
+
+	    memset(buf, 0, 64);
+	    snprintf(exe, 64, "/proc/%d/exe", lcc->pid);
+	    readlink(exe, buf, 63);
+	    if (strstr(buf, "/ssh"))
+		is_ssh = TRUE;
+	}
+#endif
 
 	if (lcc->fieldsSet & LCC_UID_SET) {
 	    uid = lcc->euid;
@@ -409,6 +422,9 @@ shm_access(ClientPtr client, SHMPERM_TYPE *perm, int readonly)
 	}
 #endif
 	FreeLocalClientCreds(lcc);
+
+	if (is_ssh)
+	    return -1;
 	
 	if (uidset) {
 	    /* User id 0 always gets access */
-- 
1.7.1