1 |
blino |
2869 |
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 |
2 |
|
|
--- Linux-PAM-1.1.3/modules/pam_console/pam_console.c.abstract 2008-12-16 13:37:52.000000000 +0100 |
3 |
|
|
+++ Linux-PAM-1.1.3/modules/pam_console/pam_console.c 2010-11-01 17:01:55.000000000 +0100 |
4 |
|
|
@@ -34,6 +34,8 @@ |
5 |
|
|
#include <sys/types.h> |
6 |
|
|
#include <sys/stat.h> |
7 |
|
|
#include <sys/param.h> |
8 |
|
|
+#include <sys/socket.h> |
9 |
|
|
+#include <sys/un.h> |
10 |
|
|
#include <fcntl.h> |
11 |
|
|
#include <unistd.h> |
12 |
|
|
#include <stdio.h> |
13 |
|
|
@@ -136,6 +138,32 @@ check_one_console_name(const char *name, |
14 |
|
|
} |
15 |
|
|
|
16 |
|
|
static int |
17 |
|
|
+try_xsocket(const char *path, size_t len) { |
18 |
|
|
+ int fd; |
19 |
|
|
+ union { |
20 |
|
|
+ struct sockaddr sa; |
21 |
|
|
+ struct sockaddr_un su; |
22 |
|
|
+ } addr; |
23 |
|
|
+ |
24 |
|
|
+ fd = socket(AF_UNIX, SOCK_STREAM, 0); |
25 |
|
|
+ if (fd < 0) |
26 |
|
|
+ return 0; |
27 |
|
|
+ |
28 |
|
|
+ memset(&addr, 0, sizeof(addr)); |
29 |
|
|
+ addr.su.sun_family = AF_UNIX; |
30 |
|
|
+ |
31 |
|
|
+ if (len > sizeof(addr.su.sun_path)) |
32 |
|
|
+ return 0; |
33 |
|
|
+ memcpy(addr.su.sun_path, path, len); |
34 |
|
|
+ if (connect(fd, &addr.sa, sizeof(addr.su)) == 0) { |
35 |
|
|
+ close(fd); |
36 |
|
|
+ return 1; |
37 |
|
|
+ } |
38 |
|
|
+ close(fd); |
39 |
|
|
+ return 0; |
40 |
|
|
+} |
41 |
|
|
+ |
42 |
|
|
+static int |
43 |
|
|
check_console_name(pam_handle_t *pamh, const char *consolename, int nonroot_ok, int on_set) { |
44 |
|
|
int found = 0; |
45 |
|
|
int statted = 0; |
46 |
|
|
@@ -186,22 +214,29 @@ check_console_name(pam_handle_t *pamh, c |
47 |
|
|
if (!statted && (consolename[0] == ':')) { |
48 |
|
|
int l; |
49 |
|
|
char *dot = NULL; |
50 |
|
|
- strcpy(full_path, "/tmp/.X11-unix/X"); |
51 |
|
|
- l = sizeof(full_path) - 1 - strlen(full_path); |
52 |
|
|
+ char *path = full_path + 1; |
53 |
|
|
+ |
54 |
|
|
+ full_path[0] = '\0'; |
55 |
|
|
+ strcpy(path, "/tmp/.X11-unix/X"); |
56 |
|
|
+ l = sizeof(full_path) - 2 - strlen(path); |
57 |
|
|
dot = strchr(consolename + 1, '.'); |
58 |
|
|
if (dot != NULL) { |
59 |
|
|
l = (l < dot - consolename - 1) ? l : dot - consolename - 1; |
60 |
|
|
} |
61 |
|
|
- strncat(full_path, consolename + 1, l); |
62 |
|
|
+ strncat(path, consolename + 1, l); |
63 |
|
|
full_path[sizeof(full_path) - 1] = '\0'; |
64 |
|
|
- _pam_log(pamh, LOG_DEBUG, TRUE, "checking possible console \"%s\"", |
65 |
|
|
- full_path); |
66 |
|
|
- if (lstat(full_path, &st) != -1) { |
67 |
|
|
+ _pam_log(pamh, LOG_DEBUG, TRUE, "checking possible X socket \"%s\"", |
68 |
|
|
+ path); |
69 |
|
|
+ |
70 |
|
|
+ /* this will work because st.st_uid is 0 */ |
71 |
|
|
+ if (try_xsocket(full_path, strlen(path)+1)) { |
72 |
|
|
+ statted = 1; |
73 |
|
|
+ } else if (try_xsocket(path, strlen(path))) { |
74 |
|
|
statted = 1; |
75 |
|
|
} |
76 |
|
|
else if (!on_set) { /* there is no X11 socket in case of X11 crash */ |
77 |
|
|
_pam_log(pamh, LOG_DEBUG, TRUE, "can't find X11 socket to examine for %s probably due to X crash", consolename); |
78 |
|
|
- statted = 1; /* this will work because st.st_uid is 0 */ |
79 |
|
|
+ statted = 1; |
80 |
|
|
} |
81 |
|
|
} |
82 |
|
|
|