Magisk/native/jni/magiskpolicy/api.cpp

91 lines
3.0 KiB
C++
Raw Normal View History

2020-03-09 08:50:30 +00:00
#include <magiskpolicy.hpp>
2019-12-09 09:14:30 +00:00
2017-04-15 11:26:29 +00:00
#include "sepolicy.h"
2017-01-31 16:51:45 +00:00
2019-11-19 10:20:18 +00:00
//#define vprint(fmt, ...) printf(fmt, __VA_ARGS__)
#define vprint(...)
2020-05-21 13:48:02 +00:00
int sepolicy::allow(const char *s, const char *t, const char *c, const char *p) {
2019-11-19 10:20:18 +00:00
vprint("allow %s %s %s %s\n", s, t, c, p);
2020-05-21 13:48:02 +00:00
return add_rule(db, s, t, c, p, AVTAB_ALLOWED, 0);
2017-01-31 16:51:45 +00:00
}
2020-05-21 13:48:02 +00:00
int sepolicy::deny(const char *s, const char *t, const char *c, const char *p) {
2019-11-19 10:20:18 +00:00
vprint("deny %s %s %s %s\n", s, t, c, p);
2020-05-21 13:48:02 +00:00
return add_rule(db, s, t, c, p, AVTAB_ALLOWED, 1);
2017-01-31 16:51:45 +00:00
}
2020-05-21 13:48:02 +00:00
int sepolicy::auditallow(const char *s, const char *t, const char *c, const char *p) {
2019-11-19 10:20:18 +00:00
vprint("auditallow %s %s %s %s\n", s, t, c, p);
2020-05-21 13:48:02 +00:00
return add_rule(db, s, t, c, p, AVTAB_AUDITALLOW, 0);
2017-01-31 16:51:45 +00:00
}
2020-05-21 13:48:02 +00:00
int sepolicy::dontaudit(const char *s, const char *t, const char *c, const char *p) {
2019-11-19 10:20:18 +00:00
vprint("dontaudit %s %s %s %s\n", s, t, c, p);
2020-05-21 13:48:02 +00:00
return add_rule(db, s, t, c, p, AVTAB_AUDITDENY, 1);
2017-01-31 16:51:45 +00:00
}
2020-05-21 13:48:02 +00:00
int sepolicy::allowxperm(const char *s, const char *t, const char *c, const char *range) {
2019-11-19 10:20:18 +00:00
vprint("allowxperm %s %s %s %s\n", s, t, c, range);
2020-05-21 13:48:02 +00:00
return add_xperm_rule(db, s, t, c, range, AVTAB_XPERMS_ALLOWED, 0);
2017-04-19 20:04:09 +00:00
}
2020-05-21 13:48:02 +00:00
int sepolicy::auditallowxperm(const char *s, const char *t, const char *c, const char *range) {
2019-11-19 10:20:18 +00:00
vprint("auditallowxperm %s %s %s %s\n", s, t, c, range);
2020-05-21 13:48:02 +00:00
return add_xperm_rule(db, s, t, c, range, AVTAB_XPERMS_AUDITALLOW, 0);
2017-04-19 20:04:09 +00:00
}
2020-05-21 13:48:02 +00:00
int sepolicy::dontauditxperm(const char *s, const char *t, const char *c, const char *range) {
2019-11-19 10:20:18 +00:00
vprint("dontauditxperm %s %s %s %s\n", s, t, c, range);
2020-05-21 13:48:02 +00:00
return add_xperm_rule(db, s, t, c, range, AVTAB_XPERMS_DONTAUDIT, 0);
2017-04-19 20:04:09 +00:00
}
2020-05-21 13:48:02 +00:00
int sepolicy::type_change(const char *s, const char *t, const char *c, const char *d) {
2019-11-19 10:20:18 +00:00
vprint("type_change %s %s %s %s\n", s, t, c, d);
2020-05-21 13:48:02 +00:00
return add_type_rule(db, s, t, c, d, AVTAB_CHANGE);
}
2020-05-21 13:48:02 +00:00
int sepolicy::type_member(const char *s, const char *t, const char *c, const char *d) {
2019-11-19 10:20:18 +00:00
vprint("type_member %s %s %s %s\n", s, t, c, d);
2020-05-21 13:48:02 +00:00
return add_type_rule(db, s, t, c, d, AVTAB_MEMBER);
}
2020-05-21 13:48:02 +00:00
int sepolicy::type_transition(const char *src, const char *tgt, const char *cls, const char *def, const char *obj) {
if (obj) {
vprint("type_transition %s %s %s %s\n", src, tgt, cls, def);
return add_type_rule(db, src, tgt, cls, def, AVTAB_TRANSITION);
} else {
vprint("type_transition %s %s %s %s %s\n", src, tgt, cls, def, obj);
return add_filename_trans(db, src, tgt, cls, def, obj);
}
2019-11-19 07:04:47 +00:00
}
2020-05-21 13:48:02 +00:00
int sepolicy::permissive(const char *s) {
2019-11-19 10:20:18 +00:00
vprint("permissive %s\n", s);
2020-05-21 13:48:02 +00:00
return set_domain_state(db, s, 1);
2017-01-31 16:51:45 +00:00
}
2020-05-21 13:48:02 +00:00
int sepolicy::enforce(const char *s) {
2019-11-19 10:20:18 +00:00
vprint("enforce %s\n", s);
2020-05-21 13:48:02 +00:00
return set_domain_state(db, s, 0);
}
2020-05-21 13:48:02 +00:00
int sepolicy::create(const char *s) {
2019-11-19 10:20:18 +00:00
vprint("create %s\n", s);
2020-05-21 13:48:02 +00:00
return create_domain(db, s);
}
2020-05-21 13:48:02 +00:00
int sepolicy::typeattribute(const char *type, const char *attr) {
vprint("typeattribute %s %s\n", type, attr);
return add_typeattribute(db, type, attr);
2017-01-31 16:51:45 +00:00
}
2020-05-21 13:48:02 +00:00
int sepolicy::genfscon(const char *fs_name, const char *path, const char *ctx) {
vprint("genfscon %s %s %s\n", fs_name, path, ctx);
return add_genfscon(db, fs_name, path, ctx);
}
2020-05-21 13:48:02 +00:00
int sepolicy::exists(const char *source) {
return hashtab_search(db->p_types.table, source) != nullptr;
2017-01-31 16:51:45 +00:00
}