src/shared/socket-label.c \
src/shared/label.c \
src/shared/label.h \
+ src/shared/selinux-util.c \
+ src/shared/selinux-util.h \
src/shared/mkdir.c \
src/shared/mkdir.h \
src/shared/ask-password-api.c \
#include "dbus-unit.h"
#include "dbus-automount.h"
#include "dbus-common.h"
+#include "selinux-access.h"
#define BUS_AUTOMOUNT_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Automount\">\n" \
{ NULL, }
};
+ SELINUX_UNIT_ACCESS_CHECK(u, c, message, "status");
+
return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps);
}
#include "dbus-unit.h"
#include "dbus-device.h"
#include "dbus-common.h"
+#include "selinux-access.h"
#define BUS_DEVICE_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Device\">\n" \
{ NULL, }
};
+ SELINUX_UNIT_ACCESS_CHECK(u, c, message, "status");
+
return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps);
}
#include "log.h"
#include "dbus-job.h"
#include "dbus-common.h"
+#include "selinux-access.h"
#define BUS_JOB_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Job\">\n" \
if (!dbus_message_iter_open_container(i, DBUS_TYPE_STRUCT, NULL, &sub))
return -ENOMEM;
- if (!(p = unit_dbus_path(j->unit)))
+ p = unit_dbus_path(j->unit);
+ if (!p)
return -ENOMEM;
if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &j->unit->id) ||
};
static DBusHandlerResult bus_job_message_dispatch(Job *j, DBusConnection *connection, DBusMessage *message) {
- DBusMessage *reply = NULL;
+ _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Job", "Cancel")) {
- if (!(reply = dbus_message_new_method_return(message)))
- goto oom;
- job_finish_and_invalidate(j, JOB_CANCELED, true);
+ SELINUX_UNIT_ACCESS_CHECK(j->unit, connection, message, "stop");
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+ job_finish_and_invalidate(j, JOB_CANCELED, true);
} else {
const BusBoundProperties bps[] = {
{ "org.freedesktop.systemd1.Job", bus_job_properties, j },
{ NULL, }
};
- return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, bps);
- }
- if (reply) {
- if (!dbus_connection_send(connection, reply, NULL))
- goto oom;
+ SELINUX_UNIT_ACCESS_CHECK(j->unit, connection, message, "status");
- dbus_message_unref(reply);
+ return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, bps);
}
- return DBUS_HANDLER_RESULT_HANDLED;
-
-oom:
- if (reply)
- dbus_message_unref(reply);
+ if (!dbus_connection_send(connection, reply, NULL))
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
+ return DBUS_HANDLER_RESULT_HANDLED;
}
static DBusHandlerResult bus_job_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
Manager *m = data;
Job *j;
int r;
- DBusMessage *reply;
+ _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
assert(connection);
assert(message);
Iterator i;
size_t size;
- if (!(reply = dbus_message_new_method_return(message)))
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "status");
+
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
/* We roll our own introspection code here, instead of
* need to generate our introspection string
* dynamically. */
- if (!(f = open_memstream(&introspection, &size)))
+ f = open_memstream(&introspection, &size);
+ if (!f)
goto oom;
fputs(DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
if (!dbus_connection_send(connection, reply, NULL))
goto oom;
- dbus_message_unref(reply);
-
return DBUS_HANDLER_RESULT_HANDLED;
}
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
- if ((r = manager_get_job_from_dbus_path(m, dbus_message_get_path(message), &j)) < 0) {
-
- if (r == -ENOMEM)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
-
- if (r == -ENOENT) {
- DBusError e;
-
- dbus_error_init(&e);
- dbus_set_error_const(&e, DBUS_ERROR_UNKNOWN_OBJECT, "Unknown job");
- return bus_send_error_reply(connection, message, &e, r);
- }
+ r = manager_get_job_from_dbus_path(m, dbus_message_get_path(message), &j);
+ if (r == -ENOMEM)
+ goto oom;
+ if (r == -ENOENT) {
+ DBusError e;
- return bus_send_error_reply(connection, message, NULL, r);
+ dbus_error_init(&e);
+ dbus_set_error_const(&e, DBUS_ERROR_UNKNOWN_OBJECT, "Unknown job");
+ return bus_send_error_reply(connection, message, &e, r);
}
+ if (r < 0)
+ return bus_send_error_reply(connection, message, NULL, r);
return bus_job_message_dispatch(j, connection, message);
oom:
- if (reply)
- dbus_message_unref(reply);
-
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
#include "watchdog.h"
#include "hwclock.h"
#include "path-util.h"
+#include "dbus-unit.h"
#define BUS_MANAGER_INTERFACE_BEGIN \
" <interface name=\"org.freedesktop.systemd1.Manager\">\n"
return 0;
}
-static const char *message_get_sender_with_fallback(DBusMessage *m) {
- const char *s;
-
- assert(m);
-
- if ((s = dbus_message_get_sender(m)))
- return s;
-
- /* When the message came in from a direct connection the
- * message will have no sender. We fix that here. */
-
- return ":no-sender";
-}
-
static DBusMessage *message_from_file_changes(
DBusMessage *m,
UnitFileChange *changes,
};
static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
+ _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
+ _cleanup_free_ char * path = NULL;
Manager *m = data;
-
int r;
DBusError error;
- DBusMessage *reply = NULL;
- char * path = NULL;
JobType job_type = _JOB_TYPE_INVALID;
bool reload_if_possible = false;
const char *member;
dbus_error_init(&error);
member = dbus_message_get_member(message);
- r = selinux_manager_access_check(connection, message, m, &error);
- if (r < 0)
- return bus_send_error_reply(connection, message, &error, r);
if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnit")) {
const char *name;
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
- if (!(u = manager_get_unit(m, name))) {
+ u = manager_get_unit(m, name);
+ if (!u) {
dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
return bus_send_error_reply(connection, message, &error, -ENOENT);
}
- if (!(reply = dbus_message_new_method_return(message)))
+ SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "status");
+
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
- if (!(path = unit_dbus_path(u)))
+ path = unit_dbus_path(u);
+ if (!path)
goto oom;
if (!dbus_message_append_args(
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
- if (!(u = cgroup_unit_by_pid(m, (pid_t) pid))) {
+ u = cgroup_unit_by_pid(m, (pid_t) pid);
+ if (!u) {
dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "No unit for PID %lu is loaded.", (unsigned long) pid);
return bus_send_error_reply(connection, message, &error, -ENOENT);
}
- if (!(reply = dbus_message_new_method_return(message)))
+ SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "status");
+
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
- if (!(path = unit_dbus_path(u)))
+ path = unit_dbus_path(u);
+ if (!reply)
goto oom;
if (!dbus_message_append_args(
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
- if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
+ r = manager_load_unit(m, name, NULL, &error, &u);
+ if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
- if (!(reply = dbus_message_new_method_return(message)))
+ SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "status");
+
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
- if (!(path = unit_dbus_path(u)))
+ path = unit_dbus_path(u);
+ if (!path)
goto oom;
if (!dbus_message_append_args(
return bus_send_error_reply(connection, message, &error, -ENOENT);
}
+ SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "stop");
+
r = unit_kill(u, who, signo, &error);
if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
- if (!(j = manager_get_job(m, id))) {
+ j = manager_get_job(m, id);
+ if (!j) {
dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
return bus_send_error_reply(connection, message, &error, -ENOENT);
}
- if (!(reply = dbus_message_new_method_return(message)))
+ SELINUX_UNIT_ACCESS_CHECK(j->unit, connection, message, "status");
+
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
- if (!(path = job_dbus_path(j)))
+ path = job_dbus_path(j);
+ if (!path)
goto oom;
if (!dbus_message_append_args(
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ClearJobs")) {
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "reboot");
+
manager_clear_jobs(m);
- if (!(reply = dbus_message_new_method_return(message)))
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ResetFailed")) {
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "reload");
+
manager_reset_failed(m);
- if (!(reply = dbus_message_new_method_return(message)))
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ResetFailedUnit")) {
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
- if (!(u = manager_get_unit(m, name))) {
+ u = manager_get_unit(m, name);
+ if (!u) {
dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
return bus_send_error_reply(connection, message, &error, -ENOENT);
}
+ SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "reload");
+
unit_reset_failed(u);
- if (!(reply = dbus_message_new_method_return(message)))
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ListUnits")) {
Unit *u;
const char *k;
- if (!(reply = dbus_message_new_method_return(message)))
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "status");
+
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
dbus_message_iter_init_append(reply, &iter);
f = unit_following(u);
following = f ? f->id : "";
- if (!(u_path = unit_dbus_path(u)))
+ u_path = unit_dbus_path(u);
+ if (!u_path)
goto oom;
if (u->job) {
Iterator i;
Job *j;
- if (!(reply = dbus_message_new_method_return(message)))
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "status");
+
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
dbus_message_iter_init_append(reply, &iter);
state = job_state_to_string(j->state);
type = job_type_to_string(j->type);
- if (!(j_path = job_dbus_path(j)))
+ j_path = job_dbus_path(j);
+ if (!j_path)
goto oom;
- if (!(u_path = unit_dbus_path(j->unit))) {
+ u_path = unit_dbus_path(j->unit);
+ if (!u_path) {
free(j_path);
goto oom;
}
char *client;
Set *s;
- if (!(s = BUS_CONNECTION_SUBSCRIBED(m, connection))) {
- if (!(s = set_new(string_hash_func, string_compare_func)))
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "status");
+
+ s = BUS_CONNECTION_SUBSCRIBED(m, connection);
+ if (!s) {
+ s = set_new(string_hash_func, string_compare_func);
+ if (!s)
goto oom;
- if (!(dbus_connection_set_data(connection, m->subscribed_data_slot, s, NULL))) {
+ if (!dbus_connection_set_data(connection, m->subscribed_data_slot, s, NULL)) {
set_free(s);
goto oom;
}
}
- if (!(client = strdup(message_get_sender_with_fallback(message))))
+ client = strdup(bus_message_get_sender_with_fallback(message));
+ if (!client)
goto oom;
- if ((r = set_put(s, client)) < 0) {
+ r = set_put(s, client);
+ if (r < 0) {
free(client);
return bus_send_error_reply(connection, message, NULL, r);
}
- if (!(reply = dbus_message_new_method_return(message)))
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Unsubscribe")) {
char *client;
- if (!(client = set_remove(BUS_CONNECTION_SUBSCRIBED(m, connection), (char*) message_get_sender_with_fallback(message)))) {
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "status");
+
+ client = set_remove(BUS_CONNECTION_SUBSCRIBED(m, connection), (char*) bus_message_get_sender_with_fallback(message));
+ if (!client) {
dbus_set_error(&error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed.");
return bus_send_error_reply(connection, message, &error, -ENOENT);
}
free(client);
- if (!(reply = dbus_message_new_method_return(message)))
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Dump")) {
char *dump = NULL;
size_t size;
- if (!(reply = dbus_message_new_method_return(message)))
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "status");
+
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
- if (!(f = open_memstream(&dump, &size)))
+ f = open_memstream(&dump, &size);
+ if (!f)
goto oom;
manager_dump_units(m, f, NULL);
dbus_bool_t cleanup;
Snapshot *s;
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "start");
+
if (!dbus_message_get_args(
message,
&error,
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
- if (name && name[0] == 0)
+ if (isempty(name))
name = NULL;
- if ((r = snapshot_create(m, name, cleanup, &error, &s)) < 0)
+ r = snapshot_create(m, name, cleanup, &error, &s);
+ if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
- if (!(reply = dbus_message_new_method_return(message)))
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
- if (!(path = unit_dbus_path(UNIT(s))))
+ path = unit_dbus_path(UNIT(s));
+ if (!path)
goto oom;
if (!dbus_message_append_args(
const char *k;
size_t size;
- if (!(reply = dbus_message_new_method_return(message)))
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "status");
+
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
/* We roll our own introspection code here, instead of
* need to generate our introspection string
* dynamically. */
- if (!(f = open_memstream(&introspection, &size)))
+ f = open_memstream(&introspection, &size);
+ if (!f)
goto oom;
fputs(INTROSPECTION_BEGIN, f);
if (k != u->id)
continue;
- if (!(p = bus_path_escape(k))) {
+ p = bus_path_escape(k);
+ if (!p) {
fclose(f);
free(introspection);
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reload")) {
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "reload");
+
assert(!m->queued_message);
/* Instead of sending the reply back right away, we
* after the reload is finished. That way the caller
* knows when the reload finished. */
- if (!(m->queued_message = dbus_message_new_method_return(message)))
+ m->queued_message = dbus_message_new_method_return(message);
+ if (!m->queued_message)
goto oom;
m->queued_message_connection = connection;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reexecute")) {
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "reload");
+
/* We don't send a reply back here, the client should
* just wait for us disconnecting. */
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Exit")) {
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "halt");
+
if (m->running_as == SYSTEMD_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Exit is only supported for user service managers.");
return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
- if (!(reply = dbus_message_new_method_return(message)))
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
m->exit_code = MANAGER_EXIT;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reboot")) {
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "reboot");
+
if (m->running_as != SYSTEMD_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Reboot is only supported for system managers.");
return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
- if (!(reply = dbus_message_new_method_return(message)))
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
m->exit_code = MANAGER_REBOOT;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "PowerOff")) {
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "halt");
+
if (m->running_as != SYSTEMD_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers.");
return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
- if (!(reply = dbus_message_new_method_return(message)))
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
m->exit_code = MANAGER_POWEROFF;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Halt")) {
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "halt");
+
if (m->running_as != SYSTEMD_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Halting is only supported for system managers.");
return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
- if (!(reply = dbus_message_new_method_return(message)))
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
m->exit_code = MANAGER_HALT;
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "KExec")) {
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "reboot");
+
if (m->running_as != SYSTEMD_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "kexec is only supported for system managers.");
return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
- if (!(reply = dbus_message_new_method_return(message)))
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
m->exit_code = MANAGER_KEXEC;
char *u, *v;
int k;
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "reboot");
+
if (!dbus_message_get_args(
message,
&error,
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SetEnvironment")) {
char **l = NULL, **e = NULL;
- if ((r = bus_parse_strv(message, &l)) < 0) {
- if (r == -ENOMEM)
- goto oom;
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "reboot");
+ r = bus_parse_strv(message, &l);
+ if (r == -ENOMEM)
+ goto oom;
+ if (r < 0)
return bus_send_error_reply(connection, message, NULL, r);
- }
e = strv_env_merge(2, m->environment, l);
strv_free(l);
-
if (!e)
goto oom;
- if (!(reply = dbus_message_new_method_return(message))) {
+ reply = dbus_message_new_method_return(message);
+ if (!reply) {
strv_free(e);
goto oom;
}
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnsetEnvironment")) {
char **l = NULL, **e = NULL;
- if ((r = bus_parse_strv(message, &l)) < 0) {
- if (r == -ENOMEM)
- goto oom;
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "reboot");
+ r = bus_parse_strv(message, &l);
+ if (r == -ENOMEM)
+ goto oom;
+ if (r < 0)
return bus_send_error_reply(connection, message, NULL, r);
- }
e = strv_env_delete(m->environment, 1, l);
strv_free(l);
char **l_set = NULL, **l_unset = NULL, **e = NULL, **f = NULL;
DBusMessageIter iter;
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "reboot");
+
if (!dbus_message_iter_init(message, &iter))
goto oom;
r = bus_parse_strv_iter(&iter, &l_unset);
- if (r < 0) {
- if (r == -ENOMEM)
- goto oom;
-
+ if (r == -ENOMEM)
+ goto oom;
+ if (r < 0)
return bus_send_error_reply(connection, message, NULL, r);
- }
if (!dbus_message_iter_next(&iter)) {
strv_free(l_unset);
Iterator i;
UnitFileList *item;
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "status");
+
reply = dbus_message_new_method_return(message);
if (!reply)
goto oom;
UnitFileState state;
const char *s;
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "status");
+
if (!dbus_message_get_args(
message,
&error,
dbus_bool_t runtime, force;
int carries_install_info = -1;
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, streq(member, "MaskUnitFiles") ? "disable" : "enable");
+
if (!dbus_message_iter_init(message, &iter))
goto oom;
unsigned n_changes = 0;
dbus_bool_t runtime;
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, streq(member, "UnmaskUnitFiles") ? "enable" : "disable");
+
if (!dbus_message_iter_init(message, &iter))
goto oom;
{ "org.freedesktop.systemd1.Manager", bus_manager_properties, m },
{ NULL, }
};
+
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "status");
+
return bus_default_message_handler(connection, message, NULL, INTERFACES_LIST, bps);
}
if (job_type != _JOB_TYPE_INVALID) {
const char *name, *smode, *old_name = NULL;
JobMode mode;
- Job *j;
- JobBusClient *cl;
Unit *u;
- bool b;
+ dbus_bool_t b;
if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StartUnitReplace"))
b = dbus_message_get_args(
DBUS_TYPE_STRING, &name,
DBUS_TYPE_STRING, &smode,
DBUS_TYPE_INVALID);
-
if (!b)
return bus_send_error_reply(connection, message, &error, -EINVAL);
- if (old_name)
- if (!(u = manager_get_unit(m, old_name)) ||
- !u->job ||
- u->job->type != JOB_START) {
+ if (old_name) {
+ u = manager_get_unit(m, old_name);
+ if (!u || !u->job || u->job->type != JOB_START) {
dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "No job queued for unit %s", old_name);
return bus_send_error_reply(connection, message, &error, -ENOENT);
}
+ }
-
- if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID) {
+ mode = job_mode_from_string(smode);
+ if (mode < 0) {
dbus_set_error(&error, BUS_ERROR_INVALID_JOB_MODE, "Job mode %s is invalid.", smode);
return bus_send_error_reply(connection, message, &error, -EINVAL);
}
- if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
- return bus_send_error_reply(connection, message, &error, r);
-
- if (reload_if_possible && unit_can_reload(u)) {
- if (job_type == JOB_RESTART)
- job_type = JOB_RELOAD_OR_START;
- else if (job_type == JOB_TRY_RESTART)
- 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) &&
- (u->refuse_manual_start || u->refuse_manual_stop))) {
- dbus_set_error(&error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, may be requested by dependency only.");
- return bus_send_error_reply(connection, message, &error, -EPERM);
- }
-
- if ((r = manager_add_job(m, job_type, u, mode, true, &error, &j)) < 0)
+ r = manager_load_unit(m, name, NULL, &error, &u);
+ if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
- cl = job_bus_client_new(connection, message_get_sender_with_fallback(message));
- if (!cl)
- goto oom;
-
- LIST_PREPEND(JobBusClient, client, j->bus_client_list, cl);
-
- if (!(reply = dbus_message_new_method_return(message)))
- goto oom;
-
- if (!(path = job_dbus_path(j)))
- goto oom;
-
- if (!dbus_message_append_args(
- reply,
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID))
- goto oom;
+ return bus_unit_queue_job(connection, message, u, job_type, mode, reload_if_possible);
}
- if (reply) {
+ if (reply)
if (!dbus_connection_send(connection, reply, NULL))
goto oom;
- dbus_message_unref(reply);
- }
-
- free(path);
-
return DBUS_HANDLER_RESULT_HANDLED;
oom:
- free(path);
-
- if (reply)
- dbus_message_unref(reply);
-
dbus_error_free(&error);
return DBUS_HANDLER_RESULT_NEED_MEMORY;
#include "dbus-kill.h"
#include "dbus-execute.h"
#include "dbus-common.h"
+#include "selinux-access.h"
#define BUS_MOUNT_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Mount\">\n" \
{ NULL, }
};
+ SELINUX_UNIT_ACCESS_CHECK(u, c, message, "status");
+
return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps );
}
#include "dbus-path.h"
#include "dbus-execute.h"
#include "dbus-common.h"
+#include "selinux-access.h"
#define BUS_PATH_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Path\">\n" \
{ NULL, }
};
+ SELINUX_UNIT_ACCESS_CHECK(u, c, message, "status");
+
return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps);
}
#include "dbus-kill.h"
#include "dbus-service.h"
#include "dbus-common.h"
+#include "selinux-access.h"
#define BUS_SERVICE_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Service\">\n" \
{ NULL, }
};
+ SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "status");
+
return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, bps);
}
#include "dbus-unit.h"
#include "dbus-snapshot.h"
#include "dbus-common.h"
+#include "selinux-access.h"
#define BUS_SNAPSHOT_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Snapshot\">\n" \
DBusHandlerResult bus_snapshot_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
Snapshot *s = SNAPSHOT(u);
-
- DBusMessage *reply = NULL;
+ _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
DBusError error;
dbus_error_init(&error);
if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Snapshot", "Remove")) {
+ SELINUX_UNIT_ACCESS_CHECK(u, c, message, "stop");
+
snapshot_remove(SNAPSHOT(u));
- if (!(reply = dbus_message_new_method_return(message)))
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
} else {
{ "org.freedesktop.systemd1.Snapshot", bus_snapshot_properties, s },
{ NULL, }
};
+
+ SELINUX_UNIT_ACCESS_CHECK(u, c, message, "status");
+
return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps);
}
if (reply) {
if (!dbus_connection_send(c, reply, NULL))
goto oom;
-
- dbus_message_unref(reply);
}
return DBUS_HANDLER_RESULT_HANDLED;
oom:
- if (reply)
- dbus_message_unref(reply);
-
dbus_error_free(&error);
return DBUS_HANDLER_RESULT_NEED_MEMORY;
#include "dbus-execute.h"
#include "dbus-kill.h"
#include "dbus-common.h"
+#include "selinux-access.h"
#define BUS_SOCKET_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Socket\">\n" \
{ NULL, }
};
+ SELINUX_UNIT_ACCESS_CHECK(u, c, message, "status");
+
return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps);
}
#include "dbus-execute.h"
#include "dbus-kill.h"
#include "dbus-common.h"
+#include "selinux-access.h"
#define BUS_SWAP_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Swap\">\n" \
{ NULL, }
};
+ SELINUX_UNIT_ACCESS_CHECK(u, c, message, "status");
+
return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps);
}
#include "dbus-unit.h"
#include "dbus-target.h"
#include "dbus-common.h"
+#include "selinux-access.h"
#define BUS_TARGET_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Target\">\n" \
{ NULL, }
};
+ SELINUX_UNIT_ACCESS_CHECK(u, c, message, "status");
+
return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps);
}
#include "dbus-timer.h"
#include "dbus-execute.h"
#include "dbus-common.h"
+#include "selinux-access.h"
#define BUS_TIMER_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Timer\">\n" \
{ NULL, }
};
+ SELINUX_UNIT_ACCESS_CHECK(u, c, message, "status");
+
return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps);
}
}
static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusConnection *connection, DBusMessage *message) {
- DBusMessage *reply = NULL;
- Manager *m = u->manager;
+ _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
DBusError error;
JobType job_type = _JOB_TYPE_INVALID;
- char *path = NULL;
bool reload_if_possible = false;
int r;
dbus_error_init(&error);
- r = selinux_unit_access_check(
- connection,
- message,
- m,
- u->source_path ? u->source_path : u->fragment_path,
- &error);
- if (r < 0)
- return bus_send_error_reply(connection, message, &error, r);
-
if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "Start"))
job_type = JOB_START;
else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "Stop"))
if (signo <= 0 || signo >= _NSIG)
return bus_send_error_reply(connection, message, &error, -EINVAL);
+ SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "stop");
+
r = unit_kill(u, who, signo, &error);
if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
} else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "ResetFailed")) {
+ SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "reload");
+
unit_reset_failed(u);
- if (!(reply = dbus_message_new_method_return(message)))
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
} else if (UNIT_VTABLE(u)->bus_message_handler)
if (job_type != _JOB_TYPE_INVALID) {
const char *smode;
JobMode mode;
- Job *j;
-
- 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) &&
- (u->refuse_manual_start || u->refuse_manual_stop))) {
- dbus_set_error(&error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, may be requested by dependency only.");
- return bus_send_error_reply(connection, message, &error, -EPERM);
- }
if (!dbus_message_get_args(
message,
DBUS_TYPE_INVALID))
return bus_send_error_reply(connection, message, &error, -EINVAL);
- if (reload_if_possible && unit_can_reload(u)) {
- if (job_type == JOB_RESTART)
- job_type = JOB_RELOAD_OR_START;
- else if (job_type == JOB_TRY_RESTART)
- job_type = JOB_RELOAD;
- }
-
- if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID) {
+ mode = job_mode_from_string(smode);
+ if (mode < 0) {
dbus_set_error(&error, BUS_ERROR_INVALID_JOB_MODE, "Job mode %s is invalid.", smode);
return bus_send_error_reply(connection, message, &error, -EINVAL);
}
- if ((r = manager_add_job(m, job_type, u, mode, true, &error, &j)) < 0)
- return bus_send_error_reply(connection, message, &error, r);
-
- if (!(reply = dbus_message_new_method_return(message)))
- goto oom;
-
- if (!(path = job_dbus_path(j)))
- goto oom;
-
- if (!dbus_message_append_args(
- reply,
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID))
- goto oom;
+ return bus_unit_queue_job(connection, message, u, job_type, mode, reload_if_possible);
}
- if (reply) {
+ if (reply)
if (!dbus_connection_send(connection, reply, NULL))
goto oom;
- dbus_message_unref(reply);
- }
-
- free(path);
-
return DBUS_HANDLER_RESULT_HANDLED;
oom:
- free(path);
-
- if (reply)
- dbus_message_unref(reply);
-
dbus_error_free(&error);
-
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
Manager *m = data;
Unit *u;
int r;
- DBusMessage *reply = NULL;
+ _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
DBusError error;
assert(connection);
if (streq(dbus_message_get_path(message), "/org/freedesktop/systemd1/unit")) {
/* Be nice to gdbus and return introspection data for our mid-level paths */
+ SELINUX_MANAGER_ACCESS_CHECK(m, connection, message, "status");
+
if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect")) {
char *introspection = NULL;
FILE *f;
const char *k;
size_t size;
- if (!(reply = dbus_message_new_method_return(message)))
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
/* We roll our own introspection code here, instead of
* need to generate our introspection string
* dynamically. */
- if (!(f = open_memstream(&introspection, &size)))
+ f = open_memstream(&introspection, &size);
+ if (!f)
goto oom;
fputs(DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
if (k != u->id)
continue;
- if (!(p = bus_path_escape(k))) {
+ p = bus_path_escape(k);
+ if (!p) {
fclose(f);
free(introspection);
goto oom;
if (!dbus_connection_send(connection, reply, NULL))
goto oom;
- dbus_message_unref(reply);
-
return DBUS_HANDLER_RESULT_HANDLED;
}
}
r = manager_load_unit_from_dbus_path(m, dbus_message_get_path(message), &error, &u);
- if (r < 0) {
- if (r == -ENOMEM)
- goto oom;
-
+ if (r == -ENOMEM)
+ goto oom;
+ if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
- }
return bus_unit_message_dispatch(u, connection, message);
oom:
- if (reply)
- dbus_message_unref(reply);
-
dbus_error_free(&error);
return DBUS_HANDLER_RESULT_NEED_MEMORY;
log_error("Failed to allocate unit remove signal.");
}
+DBusHandlerResult bus_unit_queue_job(
+ DBusConnection *connection,
+ DBusMessage *message,
+ Unit *u,
+ JobType type,
+ JobMode mode,
+ bool reload_if_possible) {
+
+ _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
+ _cleanup_free_ char *path = NULL;
+ Job *j;
+ JobBusClient *cl;
+ DBusError error;
+ int r;
+
+ assert(connection);
+ assert(message);
+ assert(u);
+ assert(type >= 0 && type < _JOB_TYPE_MAX);
+ assert(mode >= 0 && mode < _JOB_MODE_MAX);
+
+ dbus_error_init(&error);
+
+ if (reload_if_possible && unit_can_reload(u)) {
+ if (type == JOB_RESTART)
+ type = JOB_RELOAD_OR_START;
+ else if (type == JOB_TRY_RESTART)
+ type = JOB_RELOAD;
+ }
+
+ SELINUX_UNIT_ACCESS_CHECK(u, connection, message,
+ (type == JOB_START || type == JOB_RESTART || type == JOB_TRY_RESTART) ? "start" :
+ type == JOB_STOP ? "stop" : "reload");
+
+ if (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.", u->id);
+ return bus_send_error_reply(connection, message, &error, -EPERM);
+ }
+
+ if ((type == JOB_START && u->refuse_manual_start) ||
+ (type == JOB_STOP && u->refuse_manual_stop) ||
+ ((type == JOB_RESTART || type == JOB_TRY_RESTART) && (u->refuse_manual_start || u->refuse_manual_stop))) {
+ dbus_set_error(&error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, unit %s may be requested by dependency only.", u->id);
+ return bus_send_error_reply(connection, message, &error, -EPERM);
+ }
+
+ r = manager_add_job(u->manager, type, u, mode, true, &error, &j);
+ if (r < 0)
+ return bus_send_error_reply(connection, message, &error, r);
+
+ cl = job_bus_client_new(connection, bus_message_get_sender_with_fallback(message));
+ if (!cl)
+ goto oom;
+
+ LIST_PREPEND(JobBusClient, client, j->bus_client_list, cl);
+
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
+ goto oom;
+
+ path = job_dbus_path(j);
+ if (!path)
+ goto oom;
+
+ if (!dbus_message_append_args(
+ reply,
+ DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID))
+ goto oom;
+
+ if (!dbus_connection_send(connection, reply, NULL))
+ goto oom;
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+
+oom:
+ dbus_error_free(&error);
+
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+}
+
const BusProperty bus_unit_properties[] = {
{ "Id", bus_property_append_string, "s", offsetof(Unit, id), true },
{ "Names", bus_unit_append_names, "as", 0 },
void bus_unit_send_change_signal(Unit *u);
void bus_unit_send_removed_signal(Unit *u);
+
+DBusHandlerResult bus_unit_queue_job(
+ DBusConnection *connection,
+ DBusMessage *message,
+ Unit *u,
+ JobType type,
+ JobMode mode,
+ bool reload_if_possible);
+
extern const DBusObjectPathVTable bus_unit_vtable;
extern const char bus_unit_interface[];
#include "bus-errors.h"
#include "dbus-common.h"
#include "audit.h"
+#include "selinux-util.h"
#include <stdio.h>
#include <string.h>
#endif
#include <limits.h>
-/* FD to send audit messages to */
+static bool initialized = false;
static int audit_fd = -1;
-static int selinux_enabled = -1;
-static int first_time = 1;
-static int selinux_enforcing = 0;
struct auditstruct {
const char *path;
gid_t gid;
};
-/*
- Define a mapping between the systemd method calls and the SELinux access to check.
- We define two tables, one for access checks on unit files, and one for
- access checks for the system in general.
-
- If we do not find a match in either table, then the "undefined" system
- check will be called.
-*/
-
-static const char unit_methods[] =
- "DisableUnitFiles\0" "disable\0"
- "EnableUnitFiles\0" "enable\0"
- "GetUnit\0" "status\0"
- "GetUnitFileState\0" "status\0"
- "Kill\0" "stop\0"
- "KillUnit\0" "stop\0"
- "LinkUnitFiles\0" "enable\0"
- "MaskUnitFiles\0" "disable\0"
- "PresetUnitFiles\0" "enable\0"
- "ReenableUnitFiles\0" "enable\0"
- "ReloadOrRestart\0" "start\0"
- "ReloadOrRestartUnit\0" "start\0"
- "ReloadOrTryRestart\0" "start\0"
- "ReloadOrTryRestartUnit\0" "start\0"
- "Reload\0" "reload\0"
- "ReloadUnit\0" "reload\0"
- "ResetFailedUnit\0" "stop\0"
- "Restart\0" "start\0"
- "RestartUnit\0" "start\0"
- "Start\0" "start\0"
- "StartUnit\0" "start\0"
- "StartUnitReplace\0" "start\0"
- "Stop\0" "stop\0"
- "StopUnit\0" "stop\0"
- "TryRestart\0" "start\0"
- "TryRestartUnit\0" "start\0"
- "UnmaskUnitFiles\0" "enable\0";
-
-static const char system_methods[] =
- "ClearJobs\0" "reboot\0"
- "CreateSnapshot\0" "status\0"
- "Dump\0" "status\0"
- "Exit\0" "halt\0"
- "FlushDevices\0" "halt\0"
- "Get\0" "status\0"
- "GetAll\0" "status\0"
- "GetJob\0" "status\0"
- "GetSeat\0" "status\0"
- "GetSession\0" "status\0"
- "GetSessionByPID\0" "status\0"
- "GetUnitByPID\0" "status\0"
- "GetUser\0" "status\0"
- "Halt\0" "halt\0"
- "Introspect\0" "status\0"
- "KExec\0" "reboot\0"
- "KillSession\0" "halt\0"
- "KillUser\0" "halt\0"
- "LoadUnit\0" "reload\0"
- "ListJobs\0" "status\0"
- "ListSeats\0" "status\0"
- "ListSessions\0" "status\0"
- "ListUnits\0" "status\0"
- "ListUnitFiles\0" "status\0"
- "ListUsers\0" "status\0"
- "LockSession\0" "halt\0"
- "PowerOff\0" "halt\0"
- "Reboot\0" "reboot\0"
- "Reload\0" "reload\0"
- "Reexecute\0" "reload\0"
- "ResetFailed\0" "reload\0"
- "Subscribe\0" "status\0"
- "SwithcRoot\0" "reboot\0"
- "SetEnvironment\0" "status\0"
- "SetUserLinger\0" "halt\0"
- "TerminateSeat\0" "halt\0"
- "TerminateSession\0" "halt\0"
- "TerminateUser\0" "halt\0"
- "Unsubscribe\0" "status\0"
- "UnsetEnvironment\0" "status\0"
- "UnsetAndSetEnvironment\0" "status\0";
-
-/*
- If the admin toggles the selinux enforcment mode this callback
- will get called before the next access check
-*/
-static int setenforce_callback(int enforcing)
-{
- selinux_enforcing = enforcing;
- return 0;
-}
-
-/* This mimics dbus_bus_get_unix_user() */
static int bus_get_selinux_security_context(
DBusConnection *connection,
const char *name,
char **scon,
DBusError *error) {
- DBusMessage *m = NULL, *reply = NULL;
- int r;
+ _cleanup_dbus_message_unref_ DBusMessage *m = NULL, *reply = NULL;
m = dbus_message_new_method_call(
DBUS_SERVICE_DBUS,
DBUS_INTERFACE_DBUS,
"GetConnectionSELinuxSecurityContext");
if (!m) {
- r = -errno;
dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, NULL);
- goto finish;
+ return -ENOMEM;
}
- r = dbus_message_append_args(
- m,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_INVALID);
- if (!r) {
- r = -errno;
+ if (!dbus_message_append_args(
+ m,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_INVALID)) {
dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, NULL);
- goto finish;
+ return -ENOMEM;
}
reply = dbus_connection_send_with_reply_and_block(connection, m, -1, error);
- if (!reply) {
- r = -errno;
- goto finish;
- }
-
- r = dbus_set_error_from_message(error, reply);
- if (!r) {
- r = -errno;
- goto finish;
- }
-
- r = dbus_message_get_args(
- reply, error,
- DBUS_TYPE_STRING, scon,
- DBUS_TYPE_INVALID);
- if (!r) {
- r = -errno;
- goto finish;
- }
+ if (!reply)
+ return -EIO;
- r = 0;
-finish:
- if (m)
- dbus_message_unref(m);
+ if (dbus_set_error_from_message(error, reply))
+ return -EIO;
- if (reply)
- dbus_message_unref(reply);
+ if (!dbus_message_get_args(
+ reply, error,
+ DBUS_TYPE_STRING, scon,
+ DBUS_TYPE_INVALID))
+ return -EIO;
- return r;
+ return 0;
}
-/* This mimics dbus_bus_get_unix_user() */
static int bus_get_audit_data(
DBusConnection *connection,
const char *name,
pid = bus_get_unix_process_id(connection, name, error);
if (pid <= 0)
- return -EINVAL;
+ return -EIO;
r = audit_loginuid_from_pid(pid, &audit->loginuid);
if (r < 0)
Any time an access gets denied this callback will be called
with the aduit data. We then need to just copy the audit data into the msgbuf.
*/
-static int audit_callback(void *auditdata, security_class_t cls,
- char *msgbuf, size_t msgbufsize)
-{
+static int audit_callback(
+ void *auditdata,
+ security_class_t cls,
+ char *msgbuf,
+ size_t msgbufsize) {
+
struct auditstruct *audit = (struct auditstruct *) auditdata;
+
snprintf(msgbuf, msgbufsize,
- "auid=%d uid=%d gid=%d",
+ "auid=%d uid=%d gid=%d%s%s%s%s%s%s",
audit->loginuid,
- audit->uid, audit->gid);
-
- if (audit->path) {
- strncat(msgbuf," path=\"", msgbufsize);
- strncat(msgbuf, audit->path, msgbufsize);
- strncat(msgbuf,"\"", msgbufsize);
- }
+ audit->uid,
+ audit->gid,
+ (audit->path ? " path=\"" : ""),
+ strempty(audit->path),
+ (audit->path ? "\"" : ""),
+ (audit->cmdline ? " cmdline=\"" : ""),
+ strempty(audit->cmdline),
+ (audit->cmdline ? "\"" : ""));
- if (audit->cmdline) {
- strncat(msgbuf," cmdline=\"", msgbufsize);
- strncat(msgbuf, audit->cmdline, msgbufsize);
- strncat(msgbuf,"\"", msgbufsize);
- }
+ msgbuf[msgbufsize-1] = 0;
return 0;
}
user_avc's into the /var/log/audit/audit.log, otherwise they will be
sent to syslog.
*/
-static int log_callback(int type, const char *fmt, ...)
-{
+static int log_callback(int type, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
+
#ifdef HAVE_AUDIT
if (audit_fd >= 0) {
- char buf[LINE_MAX*2];
+ char buf[LINE_MAX];
vsnprintf(buf, sizeof(buf), fmt, ap);
- audit_log_user_avc_message(audit_fd, AUDIT_USER_AVC,
- buf, NULL, NULL, NULL, 0);
+ audit_log_user_avc_message(audit_fd, AUDIT_USER_AVC, buf, NULL, NULL, NULL, 0);
va_end(ap);
+
return 0;
}
#endif
log_metav(LOG_USER | LOG_INFO, __FILE__, __LINE__, __FUNCTION__, fmt, ap);
va_end(ap);
+
return 0;
}
If you want to cleanup memory you should need to call selinux_access_finish.
*/
static int access_init(void) {
-
- int r = -1;
+ int r;
if (avc_open(NULL, 0)) {
- log_error("avc_open failed: %m");
+ log_error("avc_open() failed: %m");
return -errno;
}
- selinux_set_callback(SELINUX_CB_AUDIT, (union selinux_callback) &audit_callback);
- selinux_set_callback(SELINUX_CB_LOG, (union selinux_callback) &log_callback);
- selinux_set_callback(SELINUX_CB_SETENFORCE, (union selinux_callback) &setenforce_callback);
+ selinux_set_callback(SELINUX_CB_AUDIT, (union selinux_callback) audit_callback);
+ selinux_set_callback(SELINUX_CB_LOG, (union selinux_callback) log_callback);
- if ((r = security_getenforce()) >= 0) {
- setenforce_callback(r);
+ if (security_getenforce() >= 0)
return 0;
- }
+
r = -errno;
avc_destroy();
+
return r;
}
static int selinux_init(Manager *m, DBusError *error) {
-
int r;
#ifdef HAVE_AUDIT
audit_fd = m->audit_fd;
#endif
- if (!first_time)
+ if (initialized)
return 0;
- if (selinux_enabled < 0)
- selinux_enabled = is_selinux_enabled() == 1;
-
- if (selinux_enabled) {
- /* if not first time is not set, then initialize access */
+ if (use_selinux()) {
r = access_init();
if (r < 0) {
dbus_set_error(error, DBUS_ERROR_ACCESS_DENIED, "Failed to initialize SELinux.");
}
}
- first_time = 0;
+ initialized = true;
return 0;
}
static int get_audit_data(
- DBusConnection *connection,
- DBusMessage *message,
- struct auditstruct *audit,
- DBusError *error) {
+ DBusConnection *connection,
+ DBusMessage *message,
+ struct auditstruct *audit,
+ DBusError *error) {
const char *sender;
- int r;
+ int r, fd;
+ struct ucred ucred;
+ socklen_t len;
sender = dbus_message_get_sender(message);
if (sender)
return bus_get_audit_data(connection, sender, audit, error);
- else {
- int fd;
- struct ucred ucred;
- socklen_t len;
- if (!dbus_connection_get_unix_fd(connection, &fd))
- return -EINVAL;
+ if (!dbus_connection_get_unix_fd(connection, &fd))
+ return -EINVAL;
- r = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &len);
- if (r < 0) {
- log_error("Failed to determine peer credentials: %m");
- return -errno;
- }
+ r = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &len);
+ if (r < 0) {
+ log_error("Failed to determine peer credentials: %m");
+ return -errno;
+ }
- audit->uid = ucred.uid;
- audit->gid = ucred.gid;
+ audit->uid = ucred.uid;
+ audit->gid = ucred.gid;
- r = audit_loginuid_from_pid(ucred.pid, &audit->loginuid);
- if (r < 0)
- return r;
+ r = audit_loginuid_from_pid(ucred.pid, &audit->loginuid);
+ if (r < 0)
+ return r;
- r = get_process_cmdline(ucred.pid, LINE_MAX, true, &audit->cmdline);
- if (r < 0)
- return r;
+ r = get_process_cmdline(ucred.pid, LINE_MAX, true, &audit->cmdline);
+ if (r < 0)
+ return r;
- return 0;
- }
+ return 0;
}
/*
connections. Whether it is on the bus or a local connection.
*/
static int get_calling_context(
- DBusConnection *connection,
- DBusMessage *message,
- security_context_t *scon,
- DBusError *error) {
+ DBusConnection *connection,
+ DBusMessage *message,
+ security_context_t *scon,
+ DBusError *error) {
const char *sender;
int r;
sender = dbus_message_get_sender(message);
if (sender) {
r = bus_get_selinux_security_context(connection, sender, scon, error);
- if (r == 0)
- return 0;
+ if (r >= 0)
+ return r;
log_debug("bus_get_selinux_security_context failed %m");
}
- r = dbus_connection_get_unix_fd(connection, &fd);
- if (! r) {
+ if (!dbus_connection_get_unix_fd(connection, &fd)) {
log_error("bus_connection_get_unix_fd failed %m");
return -EINVAL;
}
return 0;
}
-/*
- This function returns the SELinux permission to check and whether or not the
- check requires a unit file.
-*/
-static void selinux_perm_lookup(const char *method, const char **perm, bool *require_unit) {
- const char *m, *p;
-
- NULSTR_FOREACH_PAIR(m, p, unit_methods)
- if (streq(method, m)) {
- *perm = p;
- *require_unit = true;
- return;
- }
-
- NULSTR_FOREACH_PAIR(m, p, system_methods)
- if (streq(method, m)) {
- *perm = p;
- *require_unit = false;
- return;
- }
-
- *require_unit = false;
- *perm = "undefined";
-}
-
/*
This function communicates with the kernel to check whether or not it should
allow the access.
If the machine is in permissive mode it will return ok. Audit messages will
still be generated if the access would be denied in enforcing mode.
*/
-static int selinux_access_check(DBusConnection *connection, DBusMessage *message, Manager *m, DBusError *error, const char *perm, const char *path) {
- security_context_t scon = NULL;
- security_context_t fcon = NULL;
+static int selinux_access_check(
+ Manager *m,
+ DBusConnection *connection,
+ DBusMessage *message,
+ const char *path,
+ const char *permission,
+ DBusError *error) {
+
+ security_context_t scon = NULL, fcon = NULL;
int r = 0;
const char *tclass = NULL;
struct auditstruct audit;
+ assert(m);
+ assert(connection);
+ assert(message);
+ assert(permission);
+ assert(error);
+
+ r = selinux_init(m, error);
+ if (r < 0)
+ return r;
+
+ if (!use_selinux())
+ return 0;
+
+ log_debug("SELinux access check for path=%s permission=%s", strna(path), permission);
+
audit.uid = audit.loginuid = (uid_t) -1;
audit.gid = (gid_t) -1;
audit.cmdline = NULL;
audit.path = path;
r = get_calling_context(connection, message, &scon, error);
- if (r != 0) {
+ if (r < 0) {
log_error("Failed to get caller's security context on: %m");
goto finish;
}
+
if (path) {
tclass = "service";
/* get the file context of the unit file */
if (r < 0) {
dbus_set_error(error, DBUS_ERROR_ACCESS_DENIED, "Failed to get file context on %s.", path);
r = -errno;
- log_error("Failed to get security context on: %s %m",path);
+ log_error("Failed to get security context on %s: %m",path);
goto finish;
}
(void) get_audit_data(connection, message, &audit, error);
- errno= 0;
- r = selinux_check_access(scon, fcon, tclass, perm, &audit);
+ errno = 0;
+ r = selinux_check_access(scon, fcon, tclass, permission, &audit);
if (r < 0) {
+ dbus_set_error(error, DBUS_ERROR_ACCESS_DENIED, "SELinux policy denies access.");
r = -errno;
log_error("SELinux policy denies access.");
- dbus_set_error(error, DBUS_ERROR_ACCESS_DENIED, "SELinux policy denies access.");
}
- log_debug("SELinux checkaccess scon %s tcon %s tclass %s perm %s path %s cmdline %s: %d", scon, fcon, tclass, perm, path, audit.cmdline, r);
+ log_debug("SELinux access check scon=%s tcon=%s tclass=%s perm=%s path=%s cmdline=%s: %i", scon, fcon, tclass, permission, path, audit.cmdline, r);
+
finish:
free(audit.cmdline);
freecon(scon);
freecon(fcon);
- return r;
-}
-
-/*
- Clean up memory allocated in selinux_avc_init
-*/
-void selinux_access_finish(void) {
- if (!first_time)
- avc_destroy();
- first_time = 1;
-}
-
-int selinux_unit_access_check(DBusConnection *connection, DBusMessage *message, Manager *m, const char *path, DBusError *error) {
- const char *perm;
- bool require_unit;
- const char *member;
- int r;
-
- log_debug("SELinux unit access check %s\n", path);
- r = selinux_init(m, error);
- if (r < 0)
- return r;
-
- if (! selinux_enabled)
- return 0;
-
- member = dbus_message_get_member(message);
-
- selinux_perm_lookup(member, &perm, &require_unit);
- log_debug("SELinux dbus-unit Look %s up perm %s require_unit %d", member, perm, require_unit);
-
- r = selinux_access_check(connection, message, m, error, perm, path);
-
- /* if SELinux is in permissive mode return 0 */
- if (r && (security_getenforce() != 1 )) {
+ if (r && security_getenforce() != 1) {
dbus_error_init(error);
r = 0;
}
return r;
}
-int selinux_manager_access_check(DBusConnection *connection, DBusMessage *message, Manager *m, DBusError *error) {
- int r = -1;
- const char *member;
- bool require_unit;
- const char *perm;
- char *path = NULL;
-
- log_debug("SELinux manager access check\n");
- r = selinux_init(m, error);
- if (r < 0)
- return r;
-
- if (! selinux_enabled)
- return 0;
+int selinux_unit_access_check(
+ Unit *u,
+ DBusConnection *connection,
+ DBusMessage *message,
+ const char *permission,
+ DBusError *error) {
- member = dbus_message_get_member(message);
+ assert(u);
+ assert(connection);
+ assert(message);
+ assert(permission);
+ assert(error);
- selinux_perm_lookup(member, &perm, &require_unit);
- log_debug("SELinux dbus-manager Lookup %s perm %s require_unit %d", member, perm, require_unit);
+ return selinux_access_check(u->manager, connection, message, u->source_path ? u->source_path : u->fragment_path, permission, error);
+}
- if (require_unit) {
- const char *name, *smode, *old_name = NULL;
- Unit *u;
+int selinux_manager_access_check(
+ Manager *m,
+ DBusConnection *connection,
+ DBusMessage *message,
+ const char *permission,
+ DBusError *error) {
- if (! dbus_message_get_args(
- message,
- error,
- DBUS_TYPE_STRING, &old_name,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_STRING, &smode,
- DBUS_TYPE_INVALID)) {
- dbus_error_init(error);
- if (!dbus_message_get_args(
- message,
- error,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_STRING, &smode,
- DBUS_TYPE_INVALID)) {
- dbus_error_init(error);
- if (!dbus_message_get_args(
- message,
- error,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_INVALID)) {
- r = -EINVAL;
- /* This is broken for now, if I can not get a name
- return success.
- */
- log_error("SELinux dbus-manager failed to find unit %m");
- r = 0;
- goto finish;
- }
- }
- }
+ assert(m);
+ assert(connection);
+ assert(message);
+ assert(permission);
+ assert(error);
- log_debug("SELinux dbus-manager load unit %s", name);
- r = manager_load_unit(m, name, NULL, error, &u);
- if (r < 0) {
- log_error("Unit %s is not loaded.", name);
- /* This is broken for now, if I can not load a unit
- return success.
- */
- dbus_error_init(error);
- r = 0;
- goto finish;
- }
+ return selinux_access_check(m, connection, message, NULL, permission, error);
+}
- path = u->source_path ? u->source_path : u->fragment_path;
- if (!path) {
-// r = -1;
- log_error("Unit %s does not have path.", name);
- goto finish;
- }
- }
- r = selinux_access_check(connection, message, m, error, perm, path);
+void selinux_access_finish(void) {
+ if (!initialized)
+ return;
-finish:
- /* if SELinux is in permissive mode return 0 */
- if (r && (security_getenforce() != 1 )) {
- dbus_error_init(error);
- r = 0;
- }
- return r;
+ avc_destroy();
+ initialized = false;
}
#else
-int selinux_unit_access_check(DBusConnection *connection, DBusMessage *message, Manager *m, const char *path, DBusError *error) {
+
+int selinux_unit_access_check(
+ Unit *u,
+ DBusConnection *connection,
+ DBusMessage *message,
+ const char *permission,
+ DBusError *error) {
+
return 0;
}
-int selinux_manager_access_check(DBusConnection *connection, DBusMessage *message, Manager *m, DBusError *error) {
+int selinux_manager_access_check(
+ Manager *m,
+ DBusConnection *connection,
+ DBusMessage *message,
+ const char *permission,
+ DBusError *error) {
+
return 0;
}
void selinux_access_finish(void) {
}
+
#endif
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-#ifndef selinuxaccesshfoo
-#define selinuxaccesshfoo
+#pragma once
/***
This file is part of systemd.
***/
void selinux_access_finish(void);
-int selinux_manager_access_check(DBusConnection *connection, DBusMessage *message, Manager *m, DBusError *error);
-int selinux_unit_access_check(DBusConnection *connection, DBusMessage *message, Manager *m, const char *path, DBusError *error);
+int selinux_manager_access_check(Manager *manager, DBusConnection *connection, DBusMessage *message, const char *permission, DBusError *error);
+int selinux_unit_access_check(Unit *unit, DBusConnection *connection, DBusMessage *message, const char *permission, DBusError *error);
+
+#ifdef HAVE_SELINUX
+
+#define SELINUX_MANAGER_ACCESS_CHECK(manager, connection, message, permission) \
+ do { \
+ DBusError _error; \
+ int _r; \
+ DBusConnection *_c = (connection); \
+ DBusMessage *_m = (message); \
+ dbus_error_init(&_error); \
+ _r = selinux_manager_access_check((manager), _c, _m, (permission), &_error); \
+ if (_r < 0) \
+ return bus_send_error_reply(_c, _m, &_error, _r); \
+ } while (false)
+
+#define SELINUX_UNIT_ACCESS_CHECK(unit, connection, message, permission) \
+ do { \
+ DBusError _error; \
+ int _r; \
+ DBusConnection *_c = (connection); \
+ DBusMessage *_m = (message); \
+ dbus_error_init(&_error); \
+ _r = selinux_unit_access_check((unit), _c, _m, (permission), &_error); \
+ if (_r < 0) \
+ return bus_send_error_reply(_c, _m, &_error, _r); \
+ } while (false)
+
+#else
+
+#define SELINUX_MANAGER_ACCESS_CHECK(manager, connection, message, permission) do { } while (false)
+#define SELINUX_UNIT_ACCESS_CHECK(unit, connection, message, permission) do { } while (false)
+
#endif
#endif
#include "selinux-setup.h"
+#include "selinux-util.h"
+#include "label.h"
#include "mount-setup.h"
#include "macro.h"
#include "util.h"
#include "log.h"
-#include "label.h"
#ifdef HAVE_SELINUX
static int null_log(int type, const char *fmt, ...) {
char timespan[FORMAT_TIMESPAN_MAX];
char *label;
- label_retest_selinux();
+ retest_selinux();
/* Transition to the new context */
r = label_get_create_label_from_exe(SYSTEMD_BINARY_PATH, &label);
dbus_connection_set_exit_on_disconnect(bus, FALSE);
- if ((r = sync_auth(bus, error)) < 0) {
+ r = sync_auth(bus, error);
+ if (r < 0) {
dbus_connection_close(bus);
dbus_connection_unref(bus);
return r;
const BusBoundProperties *bound_properties) {
DBusError error;
- DBusMessage *reply = NULL;
+ _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
int r;
assert(c);
if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect") && introspection) {
- if (!(reply = dbus_message_new_method_return(message)))
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection, DBUS_TYPE_INVALID))
data = (char*)bp->base + p->offset;
if (p->indirect)
data = *(void**)data;
- r = p->append(&sub, property, data);
- if (r < 0) {
- if (r == -ENOMEM)
- goto oom;
- dbus_message_unref(reply);
+ r = p->append(&sub, property, data);
+ if (r == -ENOMEM)
+ goto oom;
+ if (r < 0)
return bus_send_error_reply(c, message, NULL, r);
- }
if (!dbus_message_iter_close_container(&iter, &sub))
goto oom;
return bus_send_error_reply(c, message, &error, -EINVAL);
}
- if (!(reply = dbus_message_new_method_return(message)))
+ reply = dbus_message_new_method_return(message);
+ if (!reply)
goto oom;
dbus_message_iter_init_append(reply, &iter);
if (p->indirect)
data = *(void**)data;
r = p->append(&sub3, p->property, data);
- if (r < 0) {
- if (r == -ENOMEM)
- goto oom;
-
- dbus_message_unref(reply);
+ if (r == -ENOMEM)
+ goto oom;
+ if (r < 0)
return bus_send_error_reply(c, message, NULL, r);
- }
if (!dbus_message_iter_close_container(&sub2, &sub3) ||
!dbus_message_iter_close_container(&sub, &sub2))
if (!dbus_connection_send(c, reply, NULL))
goto oom;
- dbus_message_unref(reply);
return DBUS_HANDLER_RESULT_HANDLED;
}
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
oom:
- if (reply)
- dbus_message_unref(reply);
-
dbus_error_free(&error);
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
DBusHandlerResult bus_send_error_reply(DBusConnection *c, DBusMessage *message, DBusError *berror, int error) {
- DBusMessage *reply = NULL;
+ _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
const char *name, *text;
if (berror && dbus_error_is_set(berror)) {
text = strerror(-error);
}
- if (!(reply = dbus_message_new_error(message, name, text)))
+ reply = dbus_message_new_error(message, name, text);
+ if (!reply)
goto oom;
if (!dbus_connection_send(c, reply, NULL))
goto oom;
- dbus_message_unref(reply);
-
if (berror)
dbus_error_free(berror);
dbus_message_iter_next(&sub);
}
- if (!(l = new(char*, n+1)))
+ l = new(char*, n+1);
+ if (!l)
return -ENOMEM;
dbus_message_iter_recurse(iter, &sub);
}
void bus_async_unregister_and_exit(DBusConnection *bus, const char *name) {
- DBusMessage *m = NULL;
+ _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
DBusPendingCall *pending = NULL;
assert(bus);
if (!dbus_pending_call_set_notify(pending, release_name_pending_cb, bus, NULL))
goto oom;
- dbus_message_unref(m);
dbus_pending_call_unref(pending);
return;
dbus_pending_call_cancel(pending);
dbus_pending_call_unref(pending);
}
-
- if (m)
- dbus_message_unref(m);
}
DBusHandlerResult bus_exit_idle_filter(DBusConnection *bus, DBusMessage *m, void *userdata) {
const char *name,
DBusError *error) {
- DBusMessage *m = NULL, *reply = NULL;
+ _cleanup_dbus_message_unref_ DBusMessage *m = NULL, *reply = NULL;
uint32_t pid = 0;
m = dbus_message_new_method_call(
"GetConnectionUnixProcessID");
if (!m) {
dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, NULL);
- goto finish;
+ return 0;
}
if (!dbus_message_append_args(
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID)) {
dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, NULL);
- goto finish;
+ return 0;
}
reply = dbus_connection_send_with_reply_and_block(connection, m, -1, error);
if (!reply)
- goto finish;
+ return 0;
if (dbus_set_error_from_message(error, reply))
- goto finish;
+ return 0;
if (!dbus_message_get_args(
reply, error,
DBUS_TYPE_UINT32, &pid,
DBUS_TYPE_INVALID))
- goto finish;
-
-finish:
- if (m)
- dbus_message_unref(m);
-
- if (reply)
- dbus_message_unref(reply);
+ return 0;
return (pid_t) pid;
}
int first_arg_type, ...) {
DBusError error;
- DBusMessage *m, *reply;
+ _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
+ DBusMessage *reply;
va_list ap;
int r = 0;
dbus_message_unref(reply);
finish:
- if (m)
- dbus_message_unref(m);
-
if (return_error)
*return_error = error;
else
return r;
}
+void bus_message_unrefp(DBusMessage **reply) {
+ if (!reply)
+ return;
+
+ if (!*reply)
+ return;
+
+ dbus_message_unref(*reply);
+}
+
+const char *bus_message_get_sender_with_fallback(DBusMessage *m) {
+ const char *s;
+
+ assert(m);
+
+ s = dbus_message_get_sender(m);
+ if (s)
+ return s;
+
+ /* When the message came in from a direct connection the
+ * message will have no sender. We fix that here. */
-void dbus_message_unref_p(DBusMessage **reply) {
- if (*reply)
- dbus_message_unref(*reply);
+ return ":no-sender";
}
DBusError *return_error,
int first_arg_type, ...);
-void dbus_message_unref_p(DBusMessage **reply);
-#define _cleanup_dbus_msg_unref_ __attribute__((cleanup(dbus_message_unref_p)))
+const char *bus_message_get_sender_with_fallback(DBusMessage *m);
+
+void bus_message_unrefp(DBusMessage **reply);
+
+#define _cleanup_dbus_message_unref_ __attribute__((cleanup(bus_message_unrefp)))
#include "path-util.h"
#ifdef HAVE_SELINUX
+#include "selinux-util.h"
#include <selinux/selinux.h>
#include <selinux/label.h>
static struct selabel_handle *label_hnd = NULL;
-static int use_selinux_cached = -1;
-
-static inline bool use_selinux(void) {
-
- if (use_selinux_cached < 0)
- use_selinux_cached = is_selinux_enabled() > 0;
-
- return use_selinux_cached;
-}
-
-void label_retest_selinux(void) {
- use_selinux_cached = -1;
-}
-
#endif
int label_init(const char *prefix) {
--- /dev/null
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2010 Lennart Poettering
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <selinux/selinux.h>
+
+#include "selinux-util.h"
+
+static int use_selinux_cached = -1;
+
+bool use_selinux(void) {
+
+ if (use_selinux_cached < 0)
+ use_selinux_cached = is_selinux_enabled() > 0;
+
+ return use_selinux_cached;
+}
+
+void retest_selinux(void) {
+ use_selinux_cached = -1;
+}
--- /dev/null
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+ This file is part of systemd.
+
+ Copyright 2010 Lennart Poettering
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <stdbool.h>
+
+bool use_selinux(void);
+void retest_selinux(void);
DBusConnection *bus,
const char *unit_name) {
- DBusMessage _cleanup_dbus_msg_unref_ *reply = NULL;
+ _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
DBusMessageIter iter, sub;
char *service_trigger = NULL;
const char *interface = "org.freedesktop.systemd1.Unit",
DBusError *error,
Set *s) {
- DBusMessage _cleanup_dbus_msg_unref_ *reply = NULL;
+ _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
const char *path;
int r;
_cleanup_free_ char *n, *p = NULL;