Move all permission check into daemon.cpp

This commit is contained in:
topjohnwu
2022-03-01 02:58:39 -08:00
committed by John Wu
parent be7586137c
commit 9968af0785
5 changed files with 30 additions and 24 deletions

View File

@@ -35,10 +35,6 @@ void denylist_handler(int client, const sock_cred *cred) {
int req = read_int(client);
int res = DenyResponse::ERROR;
if (req < 0 || req >= DenyRequest::END) {
goto done;
}
switch (req) {
case DenyRequest::ENFORCE:
res = enable_deny();
@@ -60,9 +56,9 @@ void denylist_handler(int client, const sock_cred *cred) {
? DenyResponse::ENFORCED : DenyResponse::NOT_ENFORCED;
break;
default:
__builtin_unreachable();
// Unknown request code
break;
}
done:
write_int(client, res);
close(client);
}

View File

@@ -401,13 +401,6 @@ static void get_moddir(int client) {
void zygisk_handler(int client, const sock_cred *cred) {
int code = read_int(client);
char buf[256];
if (code < ZygiskRequest::SETUP || code >= ZygiskRequest::END) {
write_int(client, -1);
return;
}
if (code != ZygiskRequest::PASSTHROUGH && cred->context != "u:r:zygote:s0") {
return;
}
switch (code) {
case ZygiskRequest::SETUP:
setup_files(client, cred);
@@ -429,7 +422,8 @@ void zygisk_handler(int client, const sock_cred *cred) {
get_moddir(client);
break;
default:
__builtin_unreachable();
// Unknown code
break;
}
close(client);
}

View File

@@ -173,7 +173,8 @@ int zygisk_main(int argc, char *argv[]) {
int is_64_bit = parse_int(argv[3]);
if (fcntl(client, F_GETFD) < 0)
return 1;
if (int magiskd = zygisk_request(ZygiskRequest::PASSTHROUGH); magiskd >= 0) {
if (int magiskd = connect_daemon(MainRequest::ZYGISK_PASSTHROUGH); magiskd >= 0) {
write_int(magiskd, ZygiskRequest::PASSTHROUGH);
write_int(magiskd, is_64_bit);
if (read_int(magiskd) != 0) {