From 74ad73c808ecbd4e0ccdfb1d6893b65c68647c62 Mon Sep 17 00:00:00 2001 From: netblue30 Date: Sat, 1 Oct 2016 09:36:22 -0400 Subject: x11 detection support for --audit --- src/faudit/dbus.c | 59 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 17 deletions(-) (limited to 'src/faudit/dbus.c') 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 @@ #include #include -void check_session_bus(const char *sockfile) { +// return 0 if the connection is possible +int check_unix(const char *sockfile) { assert(sockfile); - + int rv = -1; + // open socket int sock = socket(AF_UNIX, SOCK_STREAM, 0); - if (sock == -1) { - printf("GOOD: I cannot connect to session bus. If the application misbehaves, please log a bug with the application developer.\n"); - return; - } + if (sock == -1) + return rv; // connect struct sockaddr_un remote; @@ -37,35 +37,60 @@ void check_session_bus(const char *sockfile) { remote.sun_family = AF_UNIX; strcpy(remote.sun_path, sockfile); int len = strlen(remote.sun_path) + sizeof(remote.sun_family); - remote.sun_path[0] = '\0'; - if (connect(sock, (struct sockaddr *)&remote, len) == -1) { - printf("GOOD: I cannot connect to session bus. If the application misbehaves, please log a bug with the application developer.\n"); - } - else { - 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"); - } - + if (*sockfile == '@') + remote.sun_path[0] = '\0'; + if (connect(sock, (struct sockaddr *)&remote, len) == 0) + rv = 0; + close(sock); + return rv; } void dbus_test(void) { // check the session bus char *str = getenv("DBUS_SESSION_BUS_ADDRESS"); if (str) { + int rv = 0; char *bus = strdup(str); if (!bus) errExit("strdup"); - char *sockfile = strstr(bus, "unix:abstract="); - if (sockfile) { + char *sockfile; + if ((sockfile = strstr(bus, "unix:abstract=")) != NULL) { sockfile += 13; *sockfile = '@'; char *ptr = strchr(sockfile, ','); if (ptr) *ptr = '\0'; - check_session_bus(sockfile); + rv = check_unix(sockfile); + *sockfile = '@'; + if (rv == 0) + printf("MAYBE: D-Bus socket %s is available\n", sockfile); + else if (rv == -1) + printf("GOOD: cannot connect to D-Bus socket %s\n", sockfile); + } + else if ((sockfile = strstr(bus, "unix:path=")) != NULL) { + sockfile += 10; + char *ptr = strchr(sockfile, ','); + if (ptr) + *ptr = '\0'; + rv = check_unix(sockfile); + if (rv == 0) + printf("MAYBE: D-Bus socket %s is available\n", sockfile); + else if (rv == -1) + printf("GOOD: cannot connect to D-Bus socket %s\n", sockfile); + } + else if ((sockfile = strstr(bus, "tcp:host=")) != NULL) { + printf("UGLY: session bus configured for TCPcommunication.\n"); + rv = -2; } + else + printf("GOOD: cannot find a D-Bus socket\n"); + + free(bus); } + else + printf("GOOD: DBUS_SESSION_BUS_ADDRESS environment variable not configured."); } -- cgit v1.2.3-70-g09d2