chiark / gitweb /
bus-proxy: allow getpeersec() to fail
[elogind.git] / src / bus-proxyd / bus-proxyd.c
index d35d7f63b2f54a49274617939e9c1cc756cb4d1b..4f448256791cdc0912af3f52c504baed888b1c08 100644 (file)
@@ -40,7 +40,6 @@
 #include "bus-internal.h"
 #include "bus-message.h"
 #include "bus-util.h"
-#include "bus-internal.h"
 #include "build.h"
 #include "strv.h"
 #include "def.h"
@@ -373,6 +372,8 @@ static int synthetic_reply_method_error(sd_bus_message *call, const sd_bus_error
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
         int r;
 
+        assert(call);
+
         if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED)
                 return 0;
 
@@ -387,6 +388,8 @@ static int synthetic_reply_method_errno(sd_bus_message *call, int error, const s
 
         _cleanup_bus_error_free_ sd_bus_error berror = SD_BUS_ERROR_NULL;
 
+        assert(call);
+
         if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED)
                 return 0;
 
@@ -402,6 +405,8 @@ static int synthetic_reply_method_return(sd_bus_message *call, const char *types
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
         int r;
 
+        assert(call);
+
         if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED)
                 return 0;
 
@@ -426,6 +431,8 @@ static int synthetic_reply_return_strv(sd_bus_message *call, char **l) {
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
         int r;
 
+        assert(call);
+
         r = sd_bus_message_new_method_return(call, &m);
         if (r < 0)
                 return synthetic_reply_method_errno(call, r, NULL);
@@ -723,6 +730,7 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m) {
         } else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "ListQueuedOwners")) {
                 struct kdbus_cmd_name_list cmd = {};
                 struct kdbus_name_list *name_list;
+                struct kdbus_cmd_free cmd_free;
                 struct kdbus_cmd_name *name;
                 _cleanup_strv_free_ char **owners = NULL;
                 char *arg0;
@@ -743,12 +751,15 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m) {
                 name_list = (struct kdbus_name_list *) ((uint8_t *) a->kdbus_buffer + cmd.offset);
 
                 KDBUS_ITEM_FOREACH(name, name_list, names) {
+                        const char *entry_name = NULL;
+                        struct kdbus_item *item;
                         char *n;
 
-                        if (name->size <= sizeof(*name))
-                                continue;
+                        KDBUS_ITEM_FOREACH(item, name, items)
+                                if (item->type == KDBUS_ITEM_NAME)
+                                        entry_name = item->str;
 
-                        if (!streq(name->name, arg0))
+                        if (!streq_ptr(entry_name, arg0))
                                 continue;
 
                         if (asprintf(&n, ":1.%llu", (unsigned long long) name->owner_id) < 0) {
@@ -763,7 +774,10 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m) {
                         }
                 }
 
-                r = ioctl(a->input_fd, KDBUS_CMD_FREE, &cmd.offset);
+                cmd_free.flags = 0;
+                cmd_free.offset = cmd.offset;
+
+                r = ioctl(a->input_fd, KDBUS_CMD_FREE, &cmd_free);
                 if (r < 0)
                         return synthetic_reply_method_errno(m, r, NULL);
 
@@ -1132,8 +1146,13 @@ int main(int argc, char *argv[]) {
                 sd_is_socket(out_fd, AF_UNIX, 0, 0) > 0;
 
         if (is_unix) {
-                getpeercred(in_fd, &ucred);
-                getpeersec(in_fd, &peersec);
+                r = getpeercred(in_fd, &ucred);
+                if (r < 0) {
+                        log_error("Failed to get peer creds: %s", strerror(-r));
+                        goto finish;
+                }
+
+                (void) getpeersec(in_fd, &peersec);
         }
 
         if (arg_drop_privileges) {