Make magiskinit not magiskpolicy

This commit is contained in:
topjohnwu 2022-03-17 03:36:40 -07:00
parent fa8900be65
commit f008420891
4 changed files with 2 additions and 68 deletions

View File

@ -65,7 +65,6 @@ LOCAL_SRC_FILES := \
init/twostage.cpp \
init/selinux.cpp \
magiskpolicy/sepolicy.cpp \
magiskpolicy/magiskpolicy.cpp \
magiskpolicy/rules.cpp \
magiskpolicy/policydb.cpp \
magiskpolicy/statement.cpp
@ -114,14 +113,12 @@ LOCAL_STATIC_LIBRARIES := \
libsepol
LOCAL_SRC_FILES := \
core/applet_stub.cpp \
magiskpolicy/main.cpp \
magiskpolicy/sepolicy.cpp \
magiskpolicy/magiskpolicy.cpp \
magiskpolicy/rules.cpp \
magiskpolicy/policydb.cpp \
magiskpolicy/statement.cpp
LOCAL_CFLAGS := -DAPPLET_STUB_MAIN=magiskpolicy_main
include $(BUILD_EXECUTABLE)
endif

View File

@ -30,7 +30,6 @@ extern std::string MAGISKTMP;
#define SELINUXMOCK INTLROOT "/selinux"
constexpr const char *applet_names[] = { "su", "resetprop", nullptr };
constexpr const char *init_applet[] = { "magiskpolicy", "supolicy", nullptr };
#define POST_FS_DATA_WAIT_TIME 40
#define POST_FS_DATA_SCRIPT_MAX_TIME 35
@ -40,7 +39,6 @@ extern int SDK_INT;
// Multi-call entrypoints
int magisk_main(int argc, char *argv[]);
int magiskpolicy_main(int argc, char *argv[]);
int su_client_main(int argc, char *argv[]);
int resetprop_main(int argc, char *argv[]);
int app_process_main(int argc, char *argv[]);

View File

@ -1,13 +1,10 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/sysmacros.h>
#include <fcntl.h>
#include <libgen.h>
#include <vector>
#include <xz.h>
#include <magisk.hpp>
#include <utils.hpp>
#include <binaries.h>
@ -15,12 +12,6 @@
using namespace std;
// Debug toggle
#define ENABLE_TEST 0
constexpr int (*init_applet_main[])(int, char *[]) =
{ magiskpolicy_main, magiskpolicy_main, nullptr };
bool unxz(int fd, const uint8_t *buf, size_t size) {
uint8_t out[8192];
xz_crc32_init();
@ -65,64 +56,12 @@ public:
}
};
#if ENABLE_TEST
class TestInit : public BaseInit {
public:
TestInit(char *argv[], BootConfig *cmd) : BaseInit(argv, cmd) {};
void start() override {
// Place init tests here
}
};
static int test_main(int argc, char *argv[]) {
// Log to console
cmdline_logging();
log_cb.ex = nop_ex;
// Switch to isolate namespace
xunshare(CLONE_NEWNS);
xmount(nullptr, "/", nullptr, MS_PRIVATE | MS_REC, nullptr);
// Unmount everything in reverse
vector<string> mounts;
parse_mnt("/proc/mounts", [&](mntent *me) {
if (me->mnt_dir != "/"sv)
mounts.emplace_back(me->mnt_dir);
return true;
});
for (auto &m : reversed(mounts))
xumount(m.data());
// chroot jail
chdir(dirname(argv[0]));
chroot(".");
chdir("/");
cmdline cmd{};
load_kernel_info(&cmd);
auto init = make_unique<TestInit>(argv, &cmd);
init->start();
return 1;
}
#endif // ENABLE_TEST
int main(int argc, char *argv[]) {
umask(0);
auto name = basename(argv[0]);
if (name == "magisk"sv)
return magisk_proxy_main(argc, argv);
for (int i = 0; init_applet[i]; ++i) {
if (strcmp(name, init_applet[i]) == 0)
return (*init_applet_main[i])(argc, argv);
}
#if ENABLE_TEST
if (getenv("INIT_TEST") != nullptr)
return test_main(argc, argv);
#endif
if (argc > 1 && argv[1] == "-x"sv) {
if (argc > 2 && argv[2] == "manager"sv)

View File

@ -32,7 +32,7 @@ it will load from current live policies (/sys/fs/selinux/policy)
exit(1);
}
int magiskpolicy_main(int argc, char *argv[]) {
int main(int argc, char *argv[]) {
cmdline_logging();
const char *out_file = nullptr;
vector<string_view> rule_files;