Blame SOURCES/pam-1.1.3-console-abstract.patch

904b9f
diff -up Linux-PAM-1.1.3/modules/pam_console/pam_console.c.abstract Linux-PAM-1.1.3/modules/pam_console/pam_console.c
904b9f
--- Linux-PAM-1.1.3/modules/pam_console/pam_console.c.abstract	2008-12-16 13:37:52.000000000 +0100
904b9f
+++ Linux-PAM-1.1.3/modules/pam_console/pam_console.c	2010-11-01 17:01:55.000000000 +0100
904b9f
@@ -34,6 +34,8 @@
904b9f
 #include <sys/types.h>
904b9f
 #include <sys/stat.h>
904b9f
 #include <sys/param.h>
904b9f
+#include <sys/socket.h>
904b9f
+#include <sys/un.h>
904b9f
 #include <fcntl.h>
904b9f
 #include <unistd.h>
904b9f
 #include <stdio.h>
904b9f
@@ -136,6 +138,32 @@ check_one_console_name(const char *name,
904b9f
 }
904b9f
 
904b9f
 static int
904b9f
+try_xsocket(const char *path, size_t len) {
904b9f
+    int fd;
904b9f
+    union {
904b9f
+       struct sockaddr    sa;
904b9f
+       struct sockaddr_un su;
904b9f
+    } addr;
904b9f
+
904b9f
+    fd = socket(AF_UNIX, SOCK_STREAM, 0);
904b9f
+    if (fd < 0)
904b9f
+        return 0;
904b9f
+
904b9f
+    memset(&addr, 0, sizeof(addr));
904b9f
+    addr.su.sun_family = AF_UNIX;
904b9f
+
904b9f
+    if (len > sizeof(addr.su.sun_path))
904b9f
+        return 0;
904b9f
+    memcpy(addr.su.sun_path, path, len);
904b9f
+    if (connect(fd, &addr.sa, sizeof(addr.su) - (sizeof(addr.su.sun_path) - len)) == 0) {
904b9f
+        close(fd);
904b9f
+        return 1;
904b9f
+    }
904b9f
+    close(fd);
904b9f
+    return 0;
904b9f
+}
904b9f
+
904b9f
+static int
904b9f
 check_console_name(pam_handle_t *pamh, const char *consolename, int nonroot_ok, int on_set) {
904b9f
     int found = 0;
904b9f
     int statted = 0;
904b9f
@@ -186,22 +214,29 @@ check_console_name(pam_handle_t *pamh, c
904b9f
     if (!statted && (consolename[0] == ':')) {
904b9f
         int l;
904b9f
         char *dot = NULL;
904b9f
-        strcpy(full_path, "/tmp/.X11-unix/X");
904b9f
-        l = sizeof(full_path) - 1 - strlen(full_path);
904b9f
+        char *path = full_path + 1;
904b9f
+        
904b9f
+        full_path[0] = '\0';
904b9f
+        strcpy(path, "/tmp/.X11-unix/X");
904b9f
+        l = sizeof(full_path) - 2 - strlen(path);
904b9f
         dot = strchr(consolename + 1, '.');
904b9f
         if (dot != NULL) {
904b9f
             l = (l < dot - consolename - 1) ? l : dot - consolename - 1;
904b9f
         }
904b9f
-        strncat(full_path, consolename + 1, l);
904b9f
+        strncat(path, consolename + 1, l);
904b9f
 	full_path[sizeof(full_path) - 1] = '\0';
904b9f
-        _pam_log(pamh, LOG_DEBUG, TRUE, "checking possible console \"%s\"",
904b9f
-		 full_path);
904b9f
-        if (lstat(full_path, &st) != -1) {
904b9f
+        _pam_log(pamh, LOG_DEBUG, TRUE, "checking possible X socket \"%s\"",
904b9f
+		 path);
904b9f
+
904b9f
+        /* this will work because st.st_uid is 0 */
904b9f
+        if (try_xsocket(full_path, strlen(path)+1)) {
904b9f
+           statted = 1;
904b9f
+        } else if (try_xsocket(path, strlen(path))) {
904b9f
            statted = 1;
904b9f
         }
904b9f
         else if (!on_set) {  /* there is no X11 socket in case of X11 crash */
904b9f
             _pam_log(pamh, LOG_DEBUG, TRUE, "can't find X11 socket to examine for %s probably due to X crash", consolename);
904b9f
-            statted = 1; /* this will work because st.st_uid is 0 */
904b9f
+            statted = 1; 
904b9f
         }
904b9f
     }
904b9f