Commit 951273f8 authored by topjohnwu's avatar topjohnwu

Cleanup some implementations

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