X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fcore%2Fdbus-manager.c;h=45243270338c6411495576429caa0f1c9399d622;hp=2e6bc3dfec885a02a9323c3ce3024d2b64be6677;hb=9722ef2565fdddd64deaa99d7665ca0fdafed1a5;hpb=664f88a7e653918942b858e3f387be2ebc9ebf03 diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 2e6bc3dfe..452432703 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -225,7 +225,6 @@ " \n" \ " \n" \ " \n" \ - " \n" \ " \n" \ " \n" \ " \n" \ @@ -243,7 +242,6 @@ " \n" \ " \n" \ " \n" \ - " \n" \ " \n" \ " \n" \ " \n" \ @@ -289,7 +287,6 @@ const char bus_manager_interface[] _introspect_("Manager") = BUS_MANAGER_INTERFACE; -static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_running_as, manager_running_as, ManagerRunningAs); static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_exec_output, exec_output, ExecOutput); static int bus_manager_append_tainted(DBusMessageIter *i, const char *property, void *data) { @@ -310,13 +307,14 @@ static int bus_manager_append_tainted(DBusMessageIter *i, const char *property, free(p); if (access("/proc/cgroups", F_OK) < 0) - stpcpy(e, "cgroups-missing:"); + e = stpcpy(e, "cgroups-missing:"); if (hwclock_is_localtime() > 0) - stpcpy(e, "local-hwclock:"); + e = stpcpy(e, "local-hwclock:"); - if (endswith(buf, ":")) - buf[strlen(buf)-1] = 0; + /* remove the last ':' */ + if (e != buf) + e[-1] = 0; t = buf; @@ -545,7 +543,6 @@ static const BusProperty bus_systemd_properties[] = { }; static const BusProperty bus_manager_properties[] = { - { "RunningAs", bus_manager_append_running_as, "s", offsetof(Manager, running_as) }, { "Tainted", bus_manager_append_tainted, "s", 0 }, { "InitRDTimestamp", bus_property_append_uint64, "t", offsetof(Manager, initrd_timestamp.realtime) }, { "InitRDTimestampMonotonic", bus_property_append_uint64, "t", offsetof(Manager, initrd_timestamp.monotonic) }, @@ -564,7 +561,6 @@ static const BusProperty bus_manager_properties[] = { { "ConfirmSpawn", bus_property_append_bool, "b", offsetof(Manager, confirm_spawn) }, { "ShowStatus", bus_property_append_bool, "b", offsetof(Manager, show_status) }, { "UnitPath", bus_property_append_strv, "as", offsetof(Manager, lookup_paths.unit_path), true }, - { "NotifySocket", bus_property_append_string, "s", offsetof(Manager, notify_socket), true }, { "ControlGroupHierarchy", bus_property_append_string, "s", offsetof(Manager, cgroup_hierarchy), true }, { "DefaultControllers", bus_property_append_strv, "as", offsetof(Manager, default_controllers), true }, { "DefaultStandardOutput", bus_manager_append_exec_output, "s", offsetof(Manager, default_std_output) }, @@ -1185,6 +1181,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SwitchRoot")) { const char *switch_root, *switch_root_init; char *u, *v; + int k; if (!dbus_message_get_args( message, @@ -1194,10 +1191,10 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBUS_TYPE_INVALID)) return bus_send_error_reply(connection, message, &error, -EINVAL); - if (path_equal(switch_root, "/") || !is_path(switch_root)) + if (path_equal(switch_root, "/") || !path_is_absolute(switch_root)) return bus_send_error_reply(connection, message, NULL, -EINVAL); - if (!isempty(switch_root_init) && !is_path(switch_root_init)) + if (!isempty(switch_root_init) && !path_is_absolute(switch_root_init)) return bus_send_error_reply(connection, message, NULL, -EINVAL); if (m->running_as != MANAGER_SYSTEM) { @@ -1205,6 +1202,22 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, return bus_send_error_reply(connection, message, &error, -ENOTSUP); } + /* Safety check */ + if (isempty(switch_root_init)) + k = access(switch_root, F_OK); + else { + char *p; + + p = join(switch_root, "/", switch_root_init, NULL); + if (!p) + goto oom; + + k = access(p, X_OK); + free(p); + } + if (k < 0) + return bus_send_error_reply(connection, message, NULL, -errno); + u = strdup(switch_root); if (!u) goto oom; @@ -1574,6 +1587,11 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, job_type = JOB_RELOAD; } + if (job_type == JOB_STOP && u->load_state == UNIT_ERROR && unit_active_state(u) == UNIT_INACTIVE) { + dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s not loaded.", name); + return bus_send_error_reply(connection, message, &error, -EPERM); + } + if ((job_type == JOB_START && u->refuse_manual_start) || (job_type == JOB_STOP && u->refuse_manual_stop) || ((job_type == JOB_RESTART || job_type == JOB_TRY_RESTART) &&