Commit 951273f8 authored by topjohnwu's avatar topjohnwu

Cleanup some implementations

parent 51eeb89f
......@@ -18,35 +18,35 @@ public:
static sepolicy *compile_split();
// External APIs
int to_file(c_str file);
bool to_file(c_str file);
void parse_statement(c_str stmt);
void load_rule_file(c_str file);
// Operation on types
int create(c_str type);
int permissive(c_str type);
int enforce(c_str type);
int typeattribute(c_str type, c_str attr);
int exists(c_str type);
bool create(c_str type);
bool permissive(c_str type);
bool enforce(c_str type);
bool typeattribute(c_str type, c_str attr);
bool exists(c_str type);
// Access vector rules
int allow(c_str src, c_str tgt, c_str cls, c_str perm);
int deny(c_str src, c_str tgt, c_str cls, c_str perm);
int auditallow(c_str src, c_str tgt, c_str cls, c_str perm);
int dontaudit(c_str src, c_str tgt, c_str cls, c_str perm);
bool allow(c_str src, c_str tgt, c_str cls, c_str perm);
bool deny(c_str src, c_str tgt, c_str cls, c_str perm);
bool auditallow(c_str src, c_str tgt, c_str cls, c_str perm);
bool dontaudit(c_str src, c_str tgt, c_str cls, c_str perm);
// Extended permissions access vector rules
int allowxperm(c_str src, c_str tgt, c_str cls, c_str range);
int auditallowxperm(c_str src, c_str tgt, c_str cls, c_str range);
int dontauditxperm(c_str src, c_str tgt, c_str cls, c_str range);
bool allowxperm(c_str src, c_str tgt, c_str cls, c_str range);
bool auditallowxperm(c_str src, c_str tgt, c_str cls, c_str range);
bool dontauditxperm(c_str src, c_str tgt, c_str cls, c_str range);
// Type rules
int type_transition(c_str s, c_str t, c_str c, c_str d, c_str o = nullptr);
int type_change(c_str src, c_str tgt, c_str cls, c_str def);
int type_member(c_str src, c_str tgt, c_str cls, c_str def);
bool type_transition(c_str src, c_str tgt, c_str cls, c_str def, c_str obj = nullptr);
bool type_change(c_str src, c_str tgt, c_str cls, c_str def);
bool type_member(c_str src, c_str tgt, c_str cls, c_str def);
// File system labeling
int genfscon(c_str fs_name, c_str path, c_str ctx);
bool genfscon(c_str fs_name, c_str path, c_str ctx);
// Magisk
void magisk_rules();
......
......@@ -110,12 +110,12 @@ int magiskpolicy_main(int argc, char *argv[]) {
for (; i < argc; ++i)
sepol->parse_statement(argv[i]);
if (live && sepol->to_file(SELINUX_LOAD)) {
if (live && !sepol->to_file(SELINUX_LOAD)) {
fprintf(stderr, "Cannot apply policy\n");
return 1;
}
if (out_file && sepol->to_file(out_file)) {
if (out_file && !sepol->to_file(out_file)) {
fprintf(stderr, "Cannot dump policy to %s\n", out_file);
return 1;
}
......
......@@ -189,7 +189,7 @@ sepolicy::~sepolicy() {
free(db);
}
int sepolicy::to_file(const char *file) {
bool sepolicy::to_file(const char *file) {
uint8_t *data;
size_t len;
......@@ -205,14 +205,14 @@ int sepolicy::to_file(const char *file) {
pf.fp = fp.get();
if (policydb_write(db, &pf)) {
LOGE("Fail to create policy image\n");
return 1;
return false;
}
int fd = xopen(file, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
if (fd < 0)
return 1;
return false;
xwrite(fd, data, len);
close(fd);
return 0;
return true;
}
This diff is collapsed.
......@@ -8,19 +8,17 @@ struct sepol_impl : public sepolicy {
int set_attr(const char *attr_name, int type_val);
void check_avtab_node(avtab_ptr_t node);
avtab_ptr_t get_avtab_node(avtab_key_t *key, avtab_extended_perms_t *xperms);
int add_avrule(avtab_key_t *key, int val, bool n);
int add_rule(const char *s, const char *t, const char *c, const char *p, int effect, bool n);
int add_rule(type_datum_t *src, type_datum_t *tgt, class_datum_t *cls, perm_datum_t *perm, int effect, bool n);
int add_avxrule(avtab_key_t *key, uint16_t low, uint16_t high, bool n);
int add_xperm_rule(type_datum_t *src, type_datum_t *tgt,
bool add_rule(const char *s, const char *t, const char *c, const char *p, int effect, bool n);
void add_rule(type_datum_t *src, type_datum_t *tgt, class_datum_t *cls, perm_datum_t *perm, int effect, bool n);
void add_xperm_rule(type_datum_t *src, type_datum_t *tgt,
class_datum_t *cls, uint16_t low, uint16_t high, int effect, bool n);
int add_xperm_rule(const char *s, const char *t, const char *c, const char *range, int effect, bool n);
int create_domain(const char *type_name);
int set_domain_state(const char *s, bool permissive);
int add_filename_trans(const char *s, const char *t, const char *c, const char *d, const char *o);
int add_typeattribute(const char *type, const char *attr);
int add_type_rule(const char *s, const char *t, const char *c, const char *d, int effect);
int add_genfscon(const char *fs_name, const char *path, const char *context);
bool add_xperm_rule(const char *s, const char *t, const char *c, const char *range, int effect, bool n);
bool add_type_rule(const char *s, const char *t, const char *c, const char *d, int effect);
bool add_filename_trans(const char *s, const char *t, const char *c, const char *d, const char *o);
bool add_genfscon(const char *fs_name, const char *path, const char *context);
bool create_domain(const char *type_name);
bool set_domain_state(const char *s, bool permissive);
bool add_typeattribute(const char *type, const char *attr);
void strip_dontaudit();
void allow_su_client(const char *type);
};
......
......@@ -133,7 +133,7 @@ static bool tokenize_and_check(char *stmt, vector<vector<char *>> &arr) {
template <typename Func, typename ...Args>
static void run_and_check(const Func &fn, const char *action, Args ...args) {
if (fn(args...)) {
if (!fn(args...)) {
string s = "Error in: %s";
for (int i = 0; i < sizeof...(args); ++i) s += " %s";
s += "\n";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment