aboutsummaryrefslogtreecommitdiffstats
path: root/src/faudit/dbus.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/faudit/dbus.c')
-rw-r--r--src/faudit/dbus.c59
1 files changed, 42 insertions, 17 deletions
diff --git a/src/faudit/dbus.c b/src/faudit/dbus.c
index 64f5d8ae4..d17d3922a 100644
--- a/src/faudit/dbus.c
+++ b/src/faudit/dbus.c
@@ -21,15 +21,15 @@
21#include <sys/socket.h> 21#include <sys/socket.h>
22#include <sys/un.h> 22#include <sys/un.h>
23 23
24void check_session_bus(const char *sockfile) { 24// return 0 if the connection is possible
25int check_unix(const char *sockfile) {
25 assert(sockfile); 26 assert(sockfile);
26 27 int rv = -1;
28
27 // open socket 29 // open socket
28 int sock = socket(AF_UNIX, SOCK_STREAM, 0); 30 int sock = socket(AF_UNIX, SOCK_STREAM, 0);
29 if (sock == -1) { 31 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"); 32 return rv;
31 return;
32 }
33 33
34 // connect 34 // connect
35 struct sockaddr_un remote; 35 struct sockaddr_un remote;
@@ -37,35 +37,60 @@ void check_session_bus(const char *sockfile) {
37 remote.sun_family = AF_UNIX; 37 remote.sun_family = AF_UNIX;
38 strcpy(remote.sun_path, sockfile); 38 strcpy(remote.sun_path, sockfile);
39 int len = strlen(remote.sun_path) + sizeof(remote.sun_family); 39 int len = strlen(remote.sun_path) + sizeof(remote.sun_family);
40 remote.sun_path[0] = '\0'; 40 if (*sockfile == '@')
41 if (connect(sock, (struct sockaddr *)&remote, len) == -1) { 41 remote.sun_path[0] = '\0';
42 printf("GOOD: I cannot connect to session bus. If the application misbehaves, please log a bug with the application developer.\n"); 42 if (connect(sock, (struct sockaddr *)&remote, len) == 0)
43 } 43 rv = 0;
44 else { 44
45 printf("MAYBE: I can connect to session bus. It could be a good idea to disable it by creating a new network namespace using \"--net=none\" or \"--net=eth0\".\n");
46 }
47
48 close(sock); 45 close(sock);
46 return rv;
49} 47}
50 48
51void dbus_test(void) { 49void dbus_test(void) {
52 // check the session bus 50 // check the session bus
53 char *str = getenv("DBUS_SESSION_BUS_ADDRESS"); 51 char *str = getenv("DBUS_SESSION_BUS_ADDRESS");
54 if (str) { 52 if (str) {
53 int rv = 0;
55 char *bus = strdup(str); 54 char *bus = strdup(str);
56 if (!bus) 55 if (!bus)
57 errExit("strdup"); 56 errExit("strdup");
58 char *sockfile = strstr(bus, "unix:abstract="); 57 char *sockfile;
59 if (sockfile) { 58 if ((sockfile = strstr(bus, "unix:abstract=")) != NULL) {
60 sockfile += 13; 59 sockfile += 13;
61 *sockfile = '@'; 60 *sockfile = '@';
62 char *ptr = strchr(sockfile, ','); 61 char *ptr = strchr(sockfile, ',');
63 if (ptr) 62 if (ptr)
64 *ptr = '\0'; 63 *ptr = '\0';
65 check_session_bus(sockfile); 64 rv = check_unix(sockfile);
65 *sockfile = '@';
66 if (rv == 0)
67 printf("MAYBE: D-Bus socket %s is available\n", sockfile);
68 else if (rv == -1)
69 printf("GOOD: cannot connect to D-Bus socket %s\n", sockfile);
70 }
71 else if ((sockfile = strstr(bus, "unix:path=")) != NULL) {
72 sockfile += 10;
73 char *ptr = strchr(sockfile, ',');
74 if (ptr)
75 *ptr = '\0';
76 rv = check_unix(sockfile);
77 if (rv == 0)
78 printf("MAYBE: D-Bus socket %s is available\n", sockfile);
79 else if (rv == -1)
80 printf("GOOD: cannot connect to D-Bus socket %s\n", sockfile);
81 }
82 else if ((sockfile = strstr(bus, "tcp:host=")) != NULL) {
83 printf("UGLY: session bus configured for TCPcommunication.\n");
84 rv = -2;
66 } 85 }
86 else
87 printf("GOOD: cannot find a D-Bus socket\n");
88
89
67 free(bus); 90 free(bus);
68 } 91 }
92 else
93 printf("GOOD: DBUS_SESSION_BUS_ADDRESS environment variable not configured.");
69} 94}
70 95
71 96