mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-25 08:07:43 +00:00
Clear sepolicy rules when disable/remove modules
Co-authored-by: topjohnwu <topjohnwu@gmail.com>
This commit is contained in:
parent
f562710438
commit
67845f9c21
@ -779,17 +779,40 @@ void handle_modules() {
|
|||||||
collect_modules(true);
|
collect_modules(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int check_rules_dir(char *buf, size_t sz) {
|
||||||
|
int off = ssprintf(buf, sz, "%s/%s", MAGISKTMP.data(), RULESDIR);
|
||||||
|
struct stat st1{};
|
||||||
|
struct stat st2{};
|
||||||
|
if (xstat(buf, &st1) < 0 || xstat(MODULEROOT, &st2) < 0)
|
||||||
|
return 0;
|
||||||
|
if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
|
||||||
|
return 0;
|
||||||
|
return off;
|
||||||
|
}
|
||||||
|
|
||||||
void disable_modules() {
|
void disable_modules() {
|
||||||
foreach_module([](int, auto, int modfd) {
|
char buf[4096];
|
||||||
|
int off = check_rules_dir(buf, sizeof(buf));
|
||||||
|
foreach_module([&](int, dirent *entry, int modfd) {
|
||||||
close(xopenat(modfd, "disable", O_RDONLY | O_CREAT | O_CLOEXEC, 0));
|
close(xopenat(modfd, "disable", O_RDONLY | O_CREAT | O_CLOEXEC, 0));
|
||||||
|
if (off) {
|
||||||
|
ssprintf(buf + off, sizeof(buf) - off, "/%s/%s", entry->d_name, "sepolicy.rule");
|
||||||
|
unlink(buf);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove_modules() {
|
void remove_modules() {
|
||||||
foreach_module([](int, dirent *entry, int) {
|
char buf[4096];
|
||||||
|
int off = check_rules_dir(buf, sizeof(buf));
|
||||||
|
foreach_module([&](int, dirent *entry, int) {
|
||||||
auto uninstaller = MODULEROOT + "/"s + entry->d_name + "/uninstall.sh";
|
auto uninstaller = MODULEROOT + "/"s + entry->d_name + "/uninstall.sh";
|
||||||
if (access(uninstaller.data(), F_OK) == 0)
|
if (access(uninstaller.data(), F_OK) == 0)
|
||||||
exec_script(uninstaller.data());
|
exec_script(uninstaller.data());
|
||||||
|
if (off) {
|
||||||
|
ssprintf(buf + off, sizeof(buf) - off, "/%s/%s", entry->d_name, "sepolicy.rule");
|
||||||
|
unlink(buf);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
rm_rf(MODULEROOT);
|
rm_rf(MODULEROOT);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user