You've already forked Magisk
mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-09-06 06:36:58 +00:00
Move sepolicy parsing error message into Rust
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#![feature(format_args_nl)]
|
||||
#![feature(try_blocks)]
|
||||
|
||||
use io::Cursor;
|
||||
use std::fmt::Write;
|
||||
@@ -8,7 +9,8 @@ use std::pin::Pin;
|
||||
|
||||
pub use base;
|
||||
use base::libc::{O_CLOEXEC, O_RDONLY};
|
||||
use base::{error, BufReadExt, FsPath, LoggedResult, Utf8CStr};
|
||||
use base::{BufReadExt, FsPath, LoggedResult, Utf8CStr};
|
||||
use statement::{parse_statement, print_statement_help};
|
||||
|
||||
use crate::ffi::sepolicy;
|
||||
|
||||
@@ -88,6 +90,7 @@ mod ffi {
|
||||
fn parse_statement(sepol: Pin<&mut sepolicy>, statement: Utf8CStrRef);
|
||||
fn magisk_rules(sepol: Pin<&mut sepolicy>);
|
||||
fn xperm_to_string(perm: &Xperm) -> String;
|
||||
fn print_statement_help();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +98,6 @@ trait SepolicyExt {
|
||||
fn load_rules(self: Pin<&mut Self>, rules: &[u8]);
|
||||
fn load_rule_file(self: Pin<&mut Self>, filename: &Utf8CStr);
|
||||
fn load_rules_from_reader<T: BufRead>(self: Pin<&mut Self>, reader: &mut T);
|
||||
fn parse_statement(self: Pin<&mut Self>, statement: &str);
|
||||
}
|
||||
|
||||
impl SepolicyExt for sepolicy {
|
||||
@@ -105,13 +107,12 @@ impl SepolicyExt for sepolicy {
|
||||
}
|
||||
|
||||
fn load_rule_file(self: Pin<&mut sepolicy>, filename: &Utf8CStr) {
|
||||
fn inner(sepol: Pin<&mut sepolicy>, filename: &Utf8CStr) -> LoggedResult<()> {
|
||||
let result: LoggedResult<()> = try {
|
||||
let file = FsPath::from(filename).open(O_RDONLY | O_CLOEXEC)?;
|
||||
let mut reader = BufReader::new(file);
|
||||
sepol.load_rules_from_reader(&mut reader);
|
||||
Ok(())
|
||||
}
|
||||
inner(self, filename).ok();
|
||||
self.load_rules_from_reader(&mut reader);
|
||||
};
|
||||
result.ok();
|
||||
}
|
||||
|
||||
fn load_rules_from_reader<T: BufRead>(mut self: Pin<&mut sepolicy>, reader: &mut T) {
|
||||
@@ -120,16 +121,10 @@ impl SepolicyExt for sepolicy {
|
||||
if line.is_empty() {
|
||||
return true;
|
||||
}
|
||||
self.as_mut().parse_statement(line);
|
||||
parse_statement(self.as_mut(), line);
|
||||
true
|
||||
});
|
||||
}
|
||||
|
||||
fn parse_statement(self: Pin<&mut Self>, statement: &str) {
|
||||
if statement::parse_statement(self, statement).is_err() {
|
||||
error!("sepolicy rule syntax error: {statement}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn load_rule_file(sepol: Pin<&mut sepolicy>, filename: &Utf8CStr) {
|
||||
@@ -140,10 +135,6 @@ fn load_rules(sepol: Pin<&mut sepolicy>, rules: &[u8]) {
|
||||
sepol.load_rules(rules);
|
||||
}
|
||||
|
||||
fn parse_statement(sepol: Pin<&mut sepolicy>, statement: &Utf8CStr) {
|
||||
sepol.parse_statement(statement.as_str());
|
||||
}
|
||||
|
||||
trait SepolicyMagisk {
|
||||
fn magisk_rules(self: Pin<&mut Self>);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user