]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/core/dbus-util.c
polkit: simplify bus_verify_polkit_async() + drop auth-by-cap dbus feature
[thirdparty/systemd.git] / src / core / dbus-util.c
index 6a6dd1ff41267c17139f7429ab9779664a73f568..822a17e49ff28cbf8cd0a1085923ae9b8f029cbc 100644 (file)
@@ -30,10 +30,10 @@ int bus_property_get_triggered_unit(
         return sd_bus_message_append(reply, "s", trigger ? trigger->id : NULL);
 }
 
-BUS_DEFINE_SET_TRANSIENT(mode_t, "u", uint32_t, mode_t, "%040o");
+BUS_DEFINE_SET_TRANSIENT(mode_t, "u", uint32_t, mode_t, "%04o");
 BUS_DEFINE_SET_TRANSIENT(unsigned, "u", uint32_t, unsigned, "%" PRIu32);
 
-static inline bool valid_user_group_name_or_id_relaxed(const char *u) {
+static bool valid_user_group_name_or_id_relaxed(const char *u) {
         return valid_user_group_name(u, VALID_USER_ALLOW_NUMERIC|VALID_USER_RELAX);
 }
 
@@ -93,7 +93,7 @@ int bus_set_transient_bool(
         return 1;
 }
 
-int bus_set_transient_percent(
+int bus_set_transient_tristate(
                 Unit *u,
                 const char *name,
                 int *p,
@@ -101,22 +101,17 @@ int bus_set_transient_percent(
                 UnitWriteFlags flags,
                 sd_bus_error *error) {
 
-        const char *v;
-        int r;
+        int v, r;
 
         assert(p);
 
-        r = sd_bus_message_read(message, "s", &v);
-        if (r < 0)
-                return r;
-
-        r = parse_percent(v);
+        r = sd_bus_message_read(message, "b", &v);
         if (r < 0)
                 return r;
 
         if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
-                *p = r;
-                unit_write_settingf(u, flags, name, "%s=%d%%", name, r);
+                *p = v;
+                unit_write_settingf(u, flags, name, "%s=%s", name, yes_no(v));
         }
 
         return 1;
@@ -141,16 +136,13 @@ int bus_set_transient_usec_internal(
                 return r;
 
         if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
-                char *n, ts[FORMAT_TIMESPAN_MAX];
-
                 if (fix_0)
                         *p = v != 0 ? v: USEC_INFINITY;
                 else
                         *p = v;
 
-                n = strndupa(name, strlen(name) - 4);
-                unit_write_settingf(u, flags, name, "%sSec=%s", n,
-                                    format_timespan(ts, sizeof(ts), v, USEC_PER_MSEC));
+                char *n = strndupa_safe(name, strlen(name) - 4);
+                unit_write_settingf(u, flags, name, "%sSec=%s", n, FORMAT_TIMESPAN(v, USEC_PER_MSEC));
         }
 
         return 1;
@@ -159,9 +151,7 @@ int bus_set_transient_usec_internal(
 int bus_verify_manage_units_async_full(
                 Unit *u,
                 const char *verb,
-                int capability,
                 const char *polkit_message,
-                bool interactive,
                 sd_bus_message *call,
                 sd_bus_error *error) {
 
@@ -179,11 +169,8 @@ int bus_verify_manage_units_async_full(
 
         return bus_verify_polkit_async(
                         call,
-                        capability,
                         "org.freedesktop.systemd1.manage-units",
                         details,
-                        interactive,
-                        UID_INVALID,
                         &u->manager->polkit_registry,
                         error);
 }
@@ -210,7 +197,7 @@ int bus_read_mount_options(
                 return r;
 
         while ((r = sd_bus_message_read(message, "(ss)", &partition, &mount_options)) > 0) {
-                _cleanup_free_ char *previous = NULL, *escaped = NULL;
+                _cleanup_free_ char *escaped = NULL;
                 _cleanup_free_ MountOptions *o = NULL;
                 PartitionDesignator partition_designator;
 
@@ -227,9 +214,7 @@ int bus_read_mount_options(
                 if (!escaped)
                         return -ENOMEM;
 
-                previous = TAKE_PTR(format_str);
-                format_str = strjoin(previous, previous ? separator : "", partition, ":", escaped);
-                if (!format_str)
+                if (!strextend_with_separator(&format_str, separator, partition, ":", escaped))
                         return -ENOMEM;
 
                 o = new(MountOptions, 1);
@@ -250,7 +235,7 @@ int bus_read_mount_options(
         if (r < 0)
                 return r;
 
-        if (!LIST_IS_EMPTY(options)) {
+        if (options) {
                 if (ret_format_str) {
                         char *final = strjoin(*ret_format_str, !isempty(*ret_format_str) ? separator : "", format_str);
                         if (!final)
@@ -262,3 +247,35 @@ int bus_read_mount_options(
 
         return 0;
 }
+
+int bus_property_get_activation_details(
+                sd_bus *bus,
+                const char *path,
+                const char *interface,
+                const char *property,
+                sd_bus_message *reply,
+                void *userdata,
+                sd_bus_error *error) {
+
+        ActivationDetails **details = ASSERT_PTR(userdata);
+        _cleanup_strv_free_ char **pairs = NULL;
+        int r;
+
+        assert(reply);
+
+        r = activation_details_append_pair(*details, &pairs);
+        if (r < 0)
+                return r;
+
+        r = sd_bus_message_open_container(reply, 'a', "(ss)");
+        if (r < 0)
+                return r;
+
+        STRV_FOREACH_PAIR(key, value, pairs) {
+                r = sd_bus_message_append(reply, "(ss)", *key, *value);
+                if (r < 0)
+                        return r;
+        }
+
+        return sd_bus_message_close_container(reply);
+}