[systemd-commits] src/bus-proxyd

Daniel Mack zonque at kemper.freedesktop.org
Tue Dec 23 04:41:41 PST 2014


 src/bus-proxyd/bus-proxyd.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

New commits:
commit 259ac5cd7e37c4b9bd908460fe4de030aa252025
Author: Daniel Mack <daniel at zonque.org>
Date:   Tue Dec 23 13:37:52 2014 +0100

    bus-proxyd: handle -ESRCH and -ENXIO gracefully
    
    Messages to destinations that are not currently owned by any bus connection
    will cause kdbus related function to return with either -ENXIO or -ESRCH.
    
    Such conditions should not make the proxyd terminate but send a sane
    SD_BUS_ERROR_NAME_HAS_NO_OWNER error reply to the proxied connection.

diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c
index 5d30453..d15bd83 100644
--- a/src/bus-proxyd/bus-proxyd.c
+++ b/src/bus-proxyd/bus-proxyd.c
@@ -960,6 +960,13 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m, Policy *polic
         }
 }
 
+static int handle_policy_error(sd_bus_message *m, int r) {
+        if (r == -ESRCH || r == -ENXIO)
+                return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_NAME_HAS_NO_OWNER, "Name %s is currently not owned by anyone.", m->destination);
+
+        return r;
+}
+
 static int process_policy(sd_bus *from, sd_bus *to, sd_bus_message *m, Policy *policy, const struct ucred *our_ucred, Set *owned_names) {
         int r;
 
@@ -1045,15 +1052,15 @@ static int process_policy(sd_bus *from, sd_bus *to, sd_bus_message *m, Policy *p
                                                      SD_BUS_CREDS_UID|SD_BUS_CREDS_GID|SD_BUS_CREDS_PID,
                                                      true, &destination_creds);
                         if (r < 0)
-                                return r;
+                                return handle_policy_error(m, r);
 
                         r = sd_bus_creds_get_well_known_names(destination_creds, &destination_names);
                         if (r < 0)
-                                return r;
+                                return handle_policy_error(m, r);
 
                         r = sd_bus_creds_get_unique_name(destination_creds, &destination_unique);
                         if (r < 0)
-                                return r;
+                                return handle_policy_error(m, r);
 
                         (void) sd_bus_creds_get_uid(destination_creds, &destination_uid);
                         (void) sd_bus_creds_get_gid(destination_creds, &destination_gid);



More information about the systemd-commits mailing list