#include <string.h>
#include <unistd.h>
+#ifdef HAVE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
#include "util.h"
#include "condition.h"
return streq(parameter, id);
}
+static bool test_security(const char *parameter) {
+#ifdef HAVE_SELINUX
+ if (!strcasecmp(parameter, "SELinux"))
+ return is_selinux_enabled() > 0;
+#endif
+ return false;
+}
+
bool condition_test(Condition *c) {
assert(c);
case CONDITION_VIRTUALIZATION:
return test_virtualization(c->parameter) == !c->negate;
+ case CONDITION_SECURITY:
+ return test_security(c->parameter) == !c->negate;
+
case CONDITION_NULL:
return !c->negate;
[CONDITION_DIRECTORY_NOT_EMPTY] = "ConditionDirectoryNotEmpty",
[CONDITION_KERNEL_COMMAND_LINE] = "ConditionKernelCommandLine",
[CONDITION_VIRTUALIZATION] = "ConditionVirtualization",
+ [CONDITION_SECURITY] = "ConditionSecurity",
[CONDITION_NULL] = "ConditionNull"
};
CONDITION_DIRECTORY_NOT_EMPTY,
CONDITION_KERNEL_COMMAND_LINE,
CONDITION_VIRTUALIZATION,
+ CONDITION_SECURITY,
CONDITION_NULL,
_CONDITION_TYPE_MAX,
_CONDITION_TYPE_INVALID = -1
{ "ConditionDirectoryNotEmpty", config_parse_condition_path, CONDITION_DIRECTORY_NOT_EMPTY, u, "Unit" },
{ "ConditionKernelCommandLine", config_parse_condition_string, CONDITION_KERNEL_COMMAND_LINE, u, "Unit" },
{ "ConditionVirtualization", config_parse_condition_string, CONDITION_VIRTUALIZATION, u, "Unit" },
+ { "ConditionSecurity", config_parse_condition_string, CONDITION_SECURITY, u, "Unit" },
{ "ConditionNull", config_parse_condition_null, 0, u, "Unit" },
{ "PIDFile", config_parse_path, 0, &u->service.pid_file, "Service" },