#include "condition.h"
#include "virt.h"
#include "path-util.h"
+#include "fileio.h"
Condition* condition_new(ConditionType type, const char *parameter, bool trigger, bool negate) {
Condition *c;
return v > 0 && streq(parameter, id);
}
+static bool test_apparmor_enabled(void) {
+ int r;
+ _cleanup_free_ char *p = NULL;
+
+ r = read_one_line_file("/sys/module/apparmor/parameters/enabled", &p);
+ if (r < 0)
+ return false;
+
+ return parse_boolean(p) > 0;
+}
+
static bool test_security(const char *parameter) {
#ifdef HAVE_SELINUX
if (streq(parameter, "selinux"))
return is_selinux_enabled() > 0;
#endif
+ if (streq(parameter, "apparmor"))
+ return test_apparmor_enabled();
+ if (streq(parameter, "ima"))
+ return access("/sys/kernel/security/ima/", F_OK) == 0;
+ if (streq(parameter, "smack"))
+ return access("/sys/fs/smackfs", F_OK) == 0;
return false;
}
return b;
}
+static bool test_ac_power(const char *parameter) {
+ int r;
+
+ r = parse_boolean(parameter);
+ if (r < 0)
+ return true;
+
+ return (on_ac_power() != 0) == !!r;
+}
+
bool condition_test(Condition *c) {
assert(c);
case CONDITION_HOST:
return test_host(c->parameter) == !c->negate;
+ case CONDITION_AC_POWER:
+ return test_ac_power(c->parameter) == !c->negate;
+
case CONDITION_NULL:
return !c->negate;
[CONDITION_VIRTUALIZATION] = "ConditionVirtualization",
[CONDITION_SECURITY] = "ConditionSecurity",
[CONDITION_HOST] = "ConditionHost",
+ [CONDITION_AC_POWER] = "ConditionACPower",
[CONDITION_NULL] = "ConditionNull"
};