diff options
Diffstat (limited to 'src/faudit/dbus.c')
-rw-r--r-- | src/faudit/dbus.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/faudit/dbus.c b/src/faudit/dbus.c new file mode 100644 index 000000000..5f25e7312 --- /dev/null +++ b/src/faudit/dbus.c | |||
@@ -0,0 +1,74 @@ | |||
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 <sys/un.h> | ||
23 | |||
24 | void check_session_bus(const char *sockfile) { | ||
25 | assert(sockfile); | ||
26 | |||
27 | // open socket | ||
28 | int sock = socket(AF_UNIX, SOCK_STREAM, 0); | ||
29 | if (sock == -1) { | ||
30 | printf("GOOD: I cannot connect to session bus. If the application misbehaves, please log a bug with the application developer.\n"); | ||
31 | return; | ||
32 | } | ||
33 | |||
34 | // connect | ||
35 | struct sockaddr_un remote; | ||
36 | memset(&remote, 0, sizeof(struct sockaddr_un)); | ||
37 | remote.sun_family = AF_UNIX; | ||
38 | strcpy(remote.sun_path, sockfile); | ||
39 | int len = strlen(remote.sun_path) + sizeof(remote.sun_family); | ||
40 | remote.sun_path[0] = '\0'; | ||
41 | if (connect(sock, (struct sockaddr *)&remote, len) == -1) { | ||
42 | printf("GOOD: I cannot connect to session bus. If the application misbehaves, please log a bug with the application developer.\n"); | ||
43 | } | ||
44 | else { | ||
45 | printf("MAYBE: I can connect to session bus. If this is undesirable, use \"--private-tmp\" or blacklist the socket file.\n"); | ||
46 | } | ||
47 | |||
48 | close(sock); | ||
49 | } | ||
50 | |||
51 | void dbus_test(void) { | ||
52 | // check the session bus | ||
53 | char *str = getenv("DBUS_SESSION_BUS_ADDRESS"); | ||
54 | if (str) { | ||
55 | char *bus = strdup(str); | ||
56 | if (!bus) | ||
57 | errExit("strdup"); | ||
58 | char *sockfile = strstr(bus, "unix:abstract="); | ||
59 | if (sockfile) { | ||
60 | sockfile += 13; | ||
61 | *sockfile = '@'; | ||
62 | char *ptr = strchr(sockfile, ','); | ||
63 | if (ptr) { | ||
64 | *ptr = '\0'; | ||
65 | check_session_bus(sockfile); | ||
66 | } | ||
67 | sockfile -= 13; | ||
68 | free(sockfile); | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | |||
73 | |||
74 | |||