chiark / gitweb /
core: refuse doing %h, %s, %U specifier resolving in PID 1
[elogind.git] / src / core / dbus-kill.c
index 811adb1b5acc14e8b1ef790cca56524e204ed24c..42488b1f54e97fbe85ec413908b2c5c9a4b00f06 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <errno.h>
-#include <dbus/dbus.h>
-
+#include "bus-util.h"
+#include "kill.h"
 #include "dbus-kill.h"
-#include "dbus-common.h"
+#include "bus-util.h"
 
-static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_kill_append_mode, kill_mode, KillMode);
+static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_kill_mode, kill_mode, KillMode);
 
-const BusProperty bus_kill_context_properties[] = {
-        { "KillMode",    bus_kill_append_mode,     "s", offsetof(KillContext, kill_mode)    },
-        { "KillSignal",  bus_property_append_int,  "i", offsetof(KillContext, kill_signal)  },
-        { "SendSIGKILL", bus_property_append_bool, "b", offsetof(KillContext, send_sigkill) },
-        { "SendSIGHUP",  bus_property_append_bool, "b", offsetof(KillContext, send_sighup)  },
-        {}
+const sd_bus_vtable bus_kill_vtable[] = {
+        SD_BUS_VTABLE_START(0),
+        SD_BUS_PROPERTY("KillMode", "s", property_get_kill_mode, offsetof(KillContext, kill_mode), 0),
+        SD_BUS_PROPERTY("KillSignal", "i", bus_property_get_int, offsetof(KillContext, kill_signal), 0),
+        SD_BUS_PROPERTY("SendSIGKILL", "b", bus_property_get_bool, offsetof(KillContext, send_sigkill), 0),
+        SD_BUS_PROPERTY("SendSIGHUP", "b", bus_property_get_bool,  offsetof(KillContext, send_sighup), 0),
+        SD_BUS_VTABLE_END
 };
 
 int bus_kill_context_set_transient_property(
                 Unit *u,
                 KillContext *c,
                 const char *name,
-                DBusMessageIter *i,
+                sd_bus_message *message,
                 UnitSetPropertiesMode mode,
-                DBusError *error) {
+                sd_bus_error *error) {
+
+        int r;
 
         assert(u);
         assert(c);
         assert(name);
-        assert(i);
+        assert(message);
 
         if (streq(name, "KillMode")) {
                 const char *m;
                 KillMode k;
 
-                if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_STRING)
-                        return -EINVAL;
-
-                dbus_message_iter_get_basic(i, &m);
+                r = sd_bus_message_read(message, "s", &m);
+                if (r < 0)
+                        return r;
 
                 k = kill_mode_from_string(m);
                 if (k < 0)
@@ -70,14 +71,13 @@ int bus_kill_context_set_transient_property(
                 return 1;
 
         } else if (streq(name, "SendSIGHUP")) {
+                int b;
 
-                if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_BOOLEAN)
-                        return -EINVAL;
+                r = sd_bus_message_read(message, "b", &b);
+                if (r < 0)
+                        return r;
 
                 if (mode != UNIT_CHECK) {
-                        dbus_bool_t b;
-
-                        dbus_message_iter_get_basic(i, &b);
                         c->send_sighup = b;
 
                         unit_write_drop_in_private_format(u, mode, name, "SendSIGHUP=%s\n", yes_no(b));
@@ -86,14 +86,13 @@ int bus_kill_context_set_transient_property(
                 return 1;
 
         } else if (streq(name, "SendSIGKILL")) {
+                int b;
 
-                if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_BOOLEAN)
-                        return -EINVAL;
+                r = sd_bus_message_read(message, "b", &b);
+                if (r < 0)
+                        return r;
 
                 if (mode != UNIT_CHECK) {
-                        dbus_bool_t b;
-
-                        dbus_message_iter_get_basic(i, &b);
                         c->send_sigkill = b;
 
                         unit_write_drop_in_private_format(u, mode, name, "SendSIGKILL=%s\n", yes_no(b));