Reorganize magiskpolicy source code

This commit is contained in:
topjohnwu
2022-03-29 22:26:38 -07:00
parent efb3239cbd
commit 704f91545e
11 changed files with 171 additions and 168 deletions

View File

@@ -7,9 +7,8 @@
#include <utils.hpp>
#include <stream.hpp>
#include <magiskpolicy.hpp>
#include "sepolicy.hpp"
#include "policy.hpp"
#define SHALEN 64
static bool cmp_sha256(const char *a, const char *b) {
@@ -95,8 +94,7 @@ sepolicy *sepolicy::from_data(char *data, size_t len) {
return nullptr;
}
auto sepol = new sepolicy();
sepol->db = db;
auto sepol = new sepol_impl(db);
return sepol;
}
@@ -116,8 +114,7 @@ sepolicy *sepolicy::from_file(const char *file) {
return nullptr;
}
auto sepol = new sepolicy();
sepol->db = db;
auto sepol = new sepol_impl(db);
return sepol;
}
@@ -216,8 +213,7 @@ sepolicy *sepolicy::compile_split() {
if (cil_build_policydb(db, &pdb))
return nullptr;
auto sepol = new sepolicy();
sepol->db = &pdb->p;
auto sepol = new sepol_impl(&pdb->p);
return sepol;
}
@@ -232,7 +228,7 @@ sepolicy *sepolicy::from_split() {
return sepolicy::compile_split();
}
sepolicy::~sepolicy() {
sepol_impl::~sepol_impl() {
policydb_destroy(db);
free(db);
}
@@ -241,8 +237,8 @@ bool sepolicy::to_file(const char *file) {
uint8_t *data;
size_t len;
/* No partial writes are allowed to /sys/fs/selinux/load, thus the reason why we
* first dump everything into memory, then directly call write system call */
// No partial writes are allowed to /sys/fs/selinux/load, thus the reason why we
// first dump everything into memory, then directly call write system call
auto fp = make_stream_fp<byte_stream>(data, len);
run_finally fin([=]{ free(data); });
@@ -251,7 +247,7 @@ bool sepolicy::to_file(const char *file) {
policy_file_init(&pf);
pf.type = PF_USE_STDIO;
pf.fp = fp.get();
if (policydb_write(db, &pf)) {
if (policydb_write(impl->db, &pf)) {
LOGE("Fail to create policy image\n");
return false;
}