richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
Blob Blame History Raw
From 1ea0879cf79412e27b8becdb2bbc7e0abd301a66 Mon Sep 17 00:00:00 2001
From: Lukas Nykryn <lnykryn@redhat.com>
Date: Tue, 12 Aug 2014 12:58:47 +0200
Subject: [PATCH] selinux: Check access vector for enable and disable perm for
 each unit file

---
 src/core/dbus-manager.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index 6d16c2a..cebc730 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -1581,6 +1581,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
                    dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SetDefaultTarget")) {
 
                 char **l = NULL;
+                char **i;
                 DBusMessageIter iter;
                 UnitFileScope scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
                 UnitFileChange *changes = NULL;
@@ -1588,8 +1589,6 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
                 dbus_bool_t runtime, force;
                 int carries_install_info = -1;
 
-                SELINUX_ACCESS_CHECK(connection, message, streq(member, "MaskUnitFiles") ? "disable" : "enable");
-
                 if (!dbus_message_iter_init(message, &iter))
                         goto oom;
 
@@ -1601,6 +1600,17 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
                         return bus_send_error_reply(connection, message, NULL, r);
                 }
 
+                STRV_FOREACH(i, l) {
+                        Unit *u;
+
+                        r = manager_load_unit(m, *i, NULL, NULL, &u);
+                        if (r < 0) {
+                                dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s does not exist.", *i);
+                                return bus_send_error_reply(connection, message, &error, -ENOENT);
+                        }
+                        SELINUX_UNIT_ACCESS_CHECK(u, connection, message, streq(member, "MaskUnitFiles") ? "disable" : "enable");
+                }
+
                 if (!dbus_message_iter_next(&iter) ||
                     bus_iter_get_basic_and_next(&iter, DBUS_TYPE_BOOLEAN, &runtime, true) < 0 ||
                     bus_iter_get_basic_and_next(&iter, DBUS_TYPE_BOOLEAN, &force, false) < 0) {
@@ -1644,14 +1654,13 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
                    dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnmaskUnitFiles")) {
 
                 char **l = NULL;
+                char **i;
                 DBusMessageIter iter;
                 UnitFileScope scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
                 UnitFileChange *changes = NULL;
                 unsigned n_changes = 0;
                 dbus_bool_t runtime;
 
-                SELINUX_ACCESS_CHECK(connection, message, streq(member, "UnmaskUnitFiles") ? "enable" : "disable");
-
                 if (!dbus_message_iter_init(message, &iter))
                         goto oom;
 
@@ -1669,6 +1678,17 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
                         return bus_send_error_reply(connection, message, NULL, -EIO);
                 }
 
+                STRV_FOREACH(i, l) {
+                        Unit *u;
+
+                        r = manager_load_unit(m, *i, NULL, NULL, &u);
+                        if (r < 0) {
+                                dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s does not exist.", *i);
+                                return bus_send_error_reply(connection, message, &error, -ENOENT);
+                        }
+                        SELINUX_UNIT_ACCESS_CHECK(u, connection, message, streq(member, "UnmaskUnitFiles") ? "enable" : "disable");
+                }
+
                 if (streq(member, "DisableUnitFiles"))
                         r = unit_file_disable(scope, runtime, NULL, l, &changes, &n_changes);
                 else if (streq(member, "UnmaskUnitFiles"))