diff options
author | netblue30 <netblue30@yahoo.com> | 2016-10-01 09:36:22 -0400 |
---|---|---|
committer | netblue30 <netblue30@yahoo.com> | 2016-10-01 09:36:22 -0400 |
commit | 74ad73c808ecbd4e0ccdfb1d6893b65c68647c62 (patch) | |
tree | 44dd0ad9ea6802292f7a5ac4a3e228fa65c61c82 /src/faudit/x11.c | |
parent | gimp and inkscape profiles (diff) | |
download | firejail-74ad73c808ecbd4e0ccdfb1d6893b65c68647c62.tar.gz firejail-74ad73c808ecbd4e0ccdfb1d6893b65c68647c62.tar.zst firejail-74ad73c808ecbd4e0ccdfb1d6893b65c68647c62.zip |
x11 detection support for --audit
Diffstat (limited to 'src/faudit/x11.c')
-rw-r--r-- | src/faudit/x11.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/faudit/x11.c b/src/faudit/x11.c new file mode 100644 index 000000000..e1a4bf66e --- /dev/null +++ b/src/faudit/x11.c | |||
@@ -0,0 +1,62 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014-2016 Firejail Authors | ||
3 | * | ||
4 | * This file is part of firejail project | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License along | ||
17 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
19 | */ | ||
20 | #include "faudit.h" | ||
21 | #include <sys/socket.h> | ||
22 | #include <dirent.h> | ||
23 | |||
24 | |||
25 | void x11_test(void) { | ||
26 | // check regular display 0 sockets | ||
27 | if (check_unix("/tmp/.X11-unix/X0") == 0) | ||
28 | printf("MAYBE: X11 socket /tmp/.X11-unix/X0 is available\n"); | ||
29 | |||
30 | if (check_unix("@/tmp/.X11-unix/X0") == 0) | ||
31 | printf("MAYBE: X11 socket @/tmp/.X11-unix/X0 is available\n"); | ||
32 | |||
33 | // check all unix sockets in /tmp/.X11-unix directory | ||
34 | DIR *dir; | ||
35 | if (!(dir = opendir("/tmp/.X11-unix"))) { | ||
36 | // sleep 2 seconds and try again | ||
37 | sleep(2); | ||
38 | if (!(dir = opendir("/tmp/.X11-unix"))) | ||
39 | ; | ||
40 | } | ||
41 | |||
42 | if (dir == NULL) | ||
43 | printf("GOOD: cannot open /tmp/.X11-unix directory\n"); | ||
44 | else { | ||
45 | struct dirent *entry; | ||
46 | while ((entry = readdir(dir)) != NULL) { | ||
47 | if (strcmp(entry->d_name, "X0") == 0) | ||
48 | continue; | ||
49 | if (strcmp(entry->d_name, ".") == 0) | ||
50 | continue; | ||
51 | if (strcmp(entry->d_name, "..") == 0) | ||
52 | continue; | ||
53 | char *name; | ||
54 | if (asprintf(&name, "/tmp/.X11-unix/%s", entry->d_name) == -1) | ||
55 | errExit("asprintf"); | ||
56 | if (check_unix(name) == 0) | ||
57 | printf("MAYBE: X11 socket %s is available\n", name); | ||
58 | free(name); | ||
59 | } | ||
60 | closedir(dir); | ||
61 | } | ||
62 | } | ||