84b277
From 1ea0879cf79412e27b8becdb2bbc7e0abd301a66 Mon Sep 17 00:00:00 2001
84b277
From: Lukas Nykryn <lnykryn@redhat.com>
84b277
Date: Tue, 12 Aug 2014 12:58:47 +0200
84b277
Subject: [PATCH] selinux: Check access vector for enable and disable perm for
84b277
 each unit file
84b277
84b277
---
84b277
 src/core/dbus-manager.c | 28 ++++++++++++++++++++++++----
84b277
 1 file changed, 24 insertions(+), 4 deletions(-)
84b277
84b277
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
84b277
index 6d16c2a..cebc730 100644
84b277
--- a/src/core/dbus-manager.c
84b277
+++ b/src/core/dbus-manager.c
84b277
@@ -1581,6 +1581,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
84b277
                    dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SetDefaultTarget")) {
84b277
 
84b277
                 char **l = NULL;
84b277
+                char **i;
84b277
                 DBusMessageIter iter;
84b277
                 UnitFileScope scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
84b277
                 UnitFileChange *changes = NULL;
84b277
@@ -1588,8 +1589,6 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
84b277
                 dbus_bool_t runtime, force;
84b277
                 int carries_install_info = -1;
84b277
 
84b277
-                SELINUX_ACCESS_CHECK(connection, message, streq(member, "MaskUnitFiles") ? "disable" : "enable");
84b277
-
84b277
                 if (!dbus_message_iter_init(message, &iter))
84b277
                         goto oom;
84b277
 
84b277
@@ -1601,6 +1600,17 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
84b277
                         return bus_send_error_reply(connection, message, NULL, r);
84b277
                 }
84b277
 
84b277
+                STRV_FOREACH(i, l) {
84b277
+                        Unit *u;
84b277
+
84b277
+                        r = manager_load_unit(m, *i, NULL, NULL, &u);
84b277
+                        if (r < 0) {
84b277
+                                dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s does not exist.", *i);
84b277
+                                return bus_send_error_reply(connection, message, &error, -ENOENT);
84b277
+                        }
84b277
+                        SELINUX_UNIT_ACCESS_CHECK(u, connection, message, streq(member, "MaskUnitFiles") ? "disable" : "enable");
84b277
+                }
84b277
+
84b277
                 if (!dbus_message_iter_next(&iter) ||
84b277
                     bus_iter_get_basic_and_next(&iter, DBUS_TYPE_BOOLEAN, &runtime, true) < 0 ||
84b277
                     bus_iter_get_basic_and_next(&iter, DBUS_TYPE_BOOLEAN, &force, false) < 0) {
84b277
@@ -1644,14 +1654,13 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
84b277
                    dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnmaskUnitFiles")) {
84b277
 
84b277
                 char **l = NULL;
84b277
+                char **i;
84b277
                 DBusMessageIter iter;
84b277
                 UnitFileScope scope = m->running_as == SYSTEMD_SYSTEM ? UNIT_FILE_SYSTEM : UNIT_FILE_USER;
84b277
                 UnitFileChange *changes = NULL;
84b277
                 unsigned n_changes = 0;
84b277
                 dbus_bool_t runtime;
84b277
 
84b277
-                SELINUX_ACCESS_CHECK(connection, message, streq(member, "UnmaskUnitFiles") ? "enable" : "disable");
84b277
-
84b277
                 if (!dbus_message_iter_init(message, &iter))
84b277
                         goto oom;
84b277
 
84b277
@@ -1669,6 +1678,17 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
84b277
                         return bus_send_error_reply(connection, message, NULL, -EIO);
84b277
                 }
84b277
 
84b277
+                STRV_FOREACH(i, l) {
84b277
+                        Unit *u;
84b277
+
84b277
+                        r = manager_load_unit(m, *i, NULL, NULL, &u);
84b277
+                        if (r < 0) {
84b277
+                                dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s does not exist.", *i);
84b277
+                                return bus_send_error_reply(connection, message, &error, -ENOENT);
84b277
+                        }
84b277
+                        SELINUX_UNIT_ACCESS_CHECK(u, connection, message, streq(member, "UnmaskUnitFiles") ? "enable" : "disable");
84b277
+                }
84b277
+
84b277
                 if (streq(member, "DisableUnitFiles"))
84b277
                         r = unit_file_disable(scope, runtime, NULL, l, &changes, &n_changes);
84b277
                 else if (streq(member, "UnmaskUnitFiles"))