chiark / gitweb /
bus-util: remove stray errno assignment
[elogind.git] / src / libsystemd / sd-bus / bus-util.c
index c264f2d3fdf1602cb2891070def4b930f9ae2381..28b33ab8d08a58aca23c9d329afab20bd0d8660e 100644 (file)
@@ -123,7 +123,7 @@ int bus_event_loop_with_idle(
                 if (r < 0)
                         return r;
 
-                if (r == 0 && !exiting) {
+                if (r == 0 && !exiting && idle) {
 
                         r = sd_bus_try_close(bus);
                         if (r == -EBUSY)
@@ -190,11 +190,33 @@ int bus_name_has_owner(sd_bus *c, const char *name, sd_bus_error *error) {
         return has_owner;
 }
 
+static int check_good_user(sd_bus_message *m, uid_t good_user) {
+        _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
+        uid_t sender_uid;
+        int r;
+
+        assert(m);
+
+        if (good_user == UID_INVALID)
+                return 0;
+
+        r = sd_bus_query_sender_creds(m, SD_BUS_CREDS_EUID, &creds);
+        if (r < 0)
+                return r;
+
+        r = sd_bus_creds_get_euid(creds, &sender_uid);
+        if (r < 0)
+                return r;
+
+        return sender_uid == good_user;
+}
+
 int bus_verify_polkit(
                 sd_bus_message *call,
                 int capability,
                 const char *action,
                 bool interactive,
+                uid_t good_user,
                 bool *_challenge,
                 sd_bus_error *e) {
 
@@ -203,6 +225,10 @@ int bus_verify_polkit(
         assert(call);
         assert(action);
 
+        r = check_good_user(call, good_user);
+        if (r != 0)
+                return r;
+
         r = sd_bus_query_sender_privilege(call, capability);
         if (r < 0)
                 return r;
@@ -330,6 +356,7 @@ int bus_verify_polkit_async(
                 int capability,
                 const char *action,
                 bool interactive,
+                uid_t good_user,
                 Hashmap **registry,
                 sd_bus_error *error) {
 
@@ -347,6 +374,10 @@ int bus_verify_polkit_async(
         assert(action);
         assert(registry);
 
+        r = check_good_user(call, good_user);
+        if (r != 0)
+                return r;
+
 #ifdef ENABLE_POLKIT
         q = hashmap_get(*registry, call);
         if (q) {
@@ -1371,8 +1402,7 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
 
         if (STR_IN_SET(field,
                        "CPUAccounting", "MemoryAccounting", "BlockIOAccounting",
-                       "SendSIGHUP", "SendSIGKILL",
-                       "WakeSystem")) {
+                       "SendSIGHUP", "SendSIGKILL", "WakeSystem", "DefaultDependencies")) {
 
                 r = parse_boolean(eq);
                 if (r < 0) {
@@ -1638,13 +1668,21 @@ int bus_wait_for_jobs_new(sd_bus *bus, BusWaitForJobs **ret) {
 
         d->bus = sd_bus_ref(bus);
 
+        /* When we are a bus client we match by sender. Direct
+         * connections OTOH have no initialized sender field, and
+         * hence we ignore the sender then */
         r = sd_bus_add_match(
                         bus,
                         &d->slot_job_removed,
+                        bus->bus_client ?
                         "type='signal',"
                         "sender='org.freedesktop.systemd1',"
                         "interface='org.freedesktop.systemd1.Manager',"
                         "member='JobRemoved',"
+                        "path='/org/freedesktop/systemd1'" :
+                        "type='signal',"
+                        "interface='org.freedesktop.systemd1.Manager',"
+                        "member='JobRemoved',"
                         "path='/org/freedesktop/systemd1'",
                         match_job_removed, d);
         if (r < 0)
@@ -1776,3 +1814,29 @@ int bus_wait_for_jobs_add(BusWaitForJobs *d, const char *path) {
 
         return set_put_strdup(d->jobs, path);
 }
+
+int bus_deserialize_and_dump_unit_file_changes(sd_bus_message *m, bool quiet) {
+        const char *type, *path, *source;
+        int r;
+
+        r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(sss)");
+        if (r < 0)
+                return bus_log_parse_error(r);
+
+        while ((r = sd_bus_message_read(m, "(sss)", &type, &path, &source)) > 0) {
+                if (!quiet) {
+                        if (streq(type, "symlink"))
+                                log_info("Created symlink from %s to %s.", path, source);
+                        else
+                                log_info("Removed symlink %s.", path);
+                }
+        }
+        if (r < 0)
+                return bus_log_parse_error(r);
+
+        r = sd_bus_message_exit_container(m);
+        if (r < 0)
+                return bus_log_parse_error(r);
+
+        return 0;
+}