mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-10-16 06:45:08 +00:00
Reorganize magiskpolicy source code
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user