Magisk/native/jni/magiskpolicy/api.cpp

91 lines
2.9 KiB
C++
Raw Normal View History

2020-03-09 09:50:30 +01:00
#include <magiskpolicy.hpp>
2019-12-09 10:14:30 +01:00
2017-04-15 13:26:29 +02:00
#include "sepolicy.h"
2017-01-31 17:51:45 +01:00
2019-11-19 11:20:18 +01:00
//#define vprint(fmt, ...) printf(fmt, __VA_ARGS__)
#define vprint(...)
2018-11-08 10:20:16 +01:00
int sepol_allow(const char *s, const char *t, const char *c, const char *p) {
2019-11-19 11:20:18 +01:00
vprint("allow %s %s %s %s\n", s, t, c, p);
return add_rule(s, t, c, p, AVTAB_ALLOWED, 0);
2017-01-31 17:51:45 +01:00
}
2018-11-08 10:20:16 +01:00
int sepol_deny(const char *s, const char *t, const char *c, const char *p) {
2019-11-19 11:20:18 +01:00
vprint("deny %s %s %s %s\n", s, t, c, p);
return add_rule(s, t, c, p, AVTAB_ALLOWED, 1);
2017-01-31 17:51:45 +01:00
}
2018-11-08 10:20:16 +01:00
int sepol_auditallow(const char *s, const char *t, const char *c, const char *p) {
2019-11-19 11:20:18 +01:00
vprint("auditallow %s %s %s %s\n", s, t, c, p);
return add_rule(s, t, c, p, AVTAB_AUDITALLOW, 0);
2017-01-31 17:51:45 +01:00
}
int sepol_dontaudit(const char *s, const char *t, const char *c, const char *p) {
2019-11-19 11:20:18 +01:00
vprint("dontaudit %s %s %s %s\n", s, t, c, p);
return add_rule(s, t, c, p, AVTAB_AUDITDENY, 1);
2017-01-31 17:51:45 +01:00
}
2018-11-08 10:20:16 +01:00
int sepol_allowxperm(const char *s, const char *t, const char *c, const char *range) {
2019-11-19 11:20:18 +01:00
vprint("allowxperm %s %s %s %s\n", s, t, c, range);
2017-04-19 22:04:09 +02:00
return add_xperm_rule(s, t, c, range, AVTAB_XPERMS_ALLOWED, 0);
}
2018-11-08 10:20:16 +01:00
int sepol_auditallowxperm(const char *s, const char *t, const char *c, const char *range) {
2019-11-19 11:20:18 +01:00
vprint("auditallowxperm %s %s %s %s\n", s, t, c, range);
2017-04-19 22:04:09 +02:00
return add_xperm_rule(s, t, c, range, AVTAB_XPERMS_AUDITALLOW, 0);
}
2018-11-08 10:20:16 +01:00
int sepol_dontauditxperm(const char *s, const char *t, const char *c, const char *range) {
2019-11-19 11:20:18 +01:00
vprint("dontauditxperm %s %s %s %s\n", s, t, c, range);
2017-04-19 22:04:09 +02:00
return add_xperm_rule(s, t, c, range, AVTAB_XPERMS_DONTAUDIT, 0);
}
int sepol_typetrans(const char *s, const char *t, const char *c, const char *d) {
2019-11-19 11:20:18 +01:00
vprint("type_transition %s %s %s %s\n", s, t, c, d);
return add_type_rule(s, t, c, d, AVTAB_TRANSITION);
}
int sepol_typechange(const char *s, const char *t, const char *c, const char *d) {
2019-11-19 11:20:18 +01:00
vprint("type_change %s %s %s %s\n", s, t, c, d);
return add_type_rule(s, t, c, d, AVTAB_CHANGE);
}
int sepol_typemember(const char *s, const char *t, const char *c, const char *d) {
2019-11-19 11:20:18 +01:00
vprint("type_member %s %s %s %s\n", s, t, c, d);
return add_type_rule(s, t, c, d, AVTAB_MEMBER);
}
2019-11-19 08:04:47 +01:00
int sepol_nametrans(const char *s, const char *t, const char *c, const char *d, const char *o) {
2019-11-19 11:20:18 +01:00
vprint("name_trans %s %s %s %s %s\n", s, t, c, d, o);
2019-11-19 08:04:47 +01:00
return add_filename_trans(s, t, c, d, o);
}
2018-11-08 10:20:16 +01:00
int sepol_permissive(const char *s) {
2019-11-19 11:20:18 +01:00
vprint("permissive %s\n", s);
return set_domain_state(s, 1);
2017-01-31 17:51:45 +01:00
}
2018-11-08 10:20:16 +01:00
int sepol_enforce(const char *s) {
2019-11-19 11:20:18 +01:00
vprint("enforce %s\n", s);
return set_domain_state(s, 0);
}
2018-11-08 10:20:16 +01:00
int sepol_create(const char *s) {
2019-11-19 11:20:18 +01:00
vprint("create %s\n", s);
return create_domain(s);
}
2018-11-08 10:20:16 +01:00
int sepol_attradd(const char *s, const char *a) {
2019-11-19 11:20:18 +01:00
vprint("attradd %s %s\n", s, a);
return add_typeattribute(s, a);
2017-01-31 17:51:45 +01:00
}
int sepol_genfscon(const char *name, const char *path, const char *context) {
vprint("genfscon %s %s %s\n", name, path, context);
return add_genfscon(name, path, context);
}
2018-11-08 10:20:16 +01:00
int sepol_exists(const char *source) {
2019-11-19 11:20:18 +01:00
return hashtab_search(magisk_policydb->p_types.table, source) != nullptr;
2017-01-31 17:51:45 +01:00
}