chiark / gitweb /
sd-bus: don't fail when querying creds and dbus1 refuses to tell us the selinux context
authorLennart Poettering <lennart@poettering.net>
Mon, 24 Nov 2014 21:11:53 +0000 (22:11 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 25 Nov 2014 13:28:34 +0000 (14:28 +0100)
src/libsystemd/sd-bus/bus-control.c

index 7db912b..b887d32 100644 (file)
@@ -797,6 +797,7 @@ static int bus_get_name_creds_dbus1(
                 }
 
                 if (mask & SD_BUS_CREDS_SELINUX_CONTEXT) {
+                        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
                         const void *p = NULL;
                         size_t sz = 0;
 
@@ -806,22 +807,24 @@ static int bus_get_name_creds_dbus1(
                                         "/org/freedesktop/DBus",
                                         "org.freedesktop.DBus",
                                         "GetConnectionSELinuxSecurityContext",
-                                        NULL,
+                                        &error,
                                         &reply,
                                         "s",
                                         unique ? unique : name);
-                        if (r < 0)
-                                return r;
-
-                        r = sd_bus_message_read_array(reply, 'y', &p, &sz);
-                        if (r < 0)
-                                return r;
+                        if (r < 0) {
+                                if (!sd_bus_error_has_name(&error, "org.freedesktop.DBus.Error.SELinuxSecurityContextUnknown"))
+                                        return r;
+                        } else {
+                                r = sd_bus_message_read_array(reply, 'y', &p, &sz);
+                                if (r < 0)
+                                        return r;
 
-                        c->label = strndup(p, sz);
-                        if (!c->label)
-                                return -ENOMEM;
+                                c->label = strndup(p, sz);
+                                if (!c->label)
+                                        return -ENOMEM;
 
-                        c->mask |= SD_BUS_CREDS_SELINUX_CONTEXT;
+                                c->mask |= SD_BUS_CREDS_SELINUX_CONTEXT;
+                        }
                 }
 
                 r = bus_creds_add_more(c, mask, pid, 0);