From 2e51fe20a1e7e474a6fee3648bf77ab38577396e Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 30 May 2022 02:09:07 -0700 Subject: [PATCH] Move things to the correct location --- native/jni/base/misc.hpp | 6 ------ native/jni/core/daemon.cpp | 6 +++--- native/jni/include/daemon.hpp | 5 +++++ native/jni/su/connect.cpp | 1 - native/jni/su/su.cpp | 1 - native/jni/su/su.hpp | 3 ++- native/jni/su/su_daemon.cpp | 14 ++++++-------- 7 files changed, 16 insertions(+), 20 deletions(-) diff --git a/native/jni/base/misc.hpp b/native/jni/base/misc.hpp index 683094a50..cfeac562a 100644 --- a/native/jni/base/misc.hpp +++ b/native/jni/base/misc.hpp @@ -6,16 +6,10 @@ #include #include -#define UID_ROOT 0 -#define UID_SHELL 2000 - #define DISALLOW_COPY_AND_MOVE(clazz) \ clazz(const clazz &) = delete; \ clazz(clazz &&) = delete; -#define to_app_id(uid) (uid % 100000) -#define to_user_id(uid) (uid / 100000) - class mutex_guard { DISALLOW_COPY_AND_MOVE(mutex_guard) public: diff --git a/native/jni/core/daemon.cpp b/native/jni/core/daemon.cpp index 4b457d306..070b44e40 100644 --- a/native/jni/core/daemon.cpp +++ b/native/jni/core/daemon.cpp @@ -220,7 +220,7 @@ static void handle_request(pollfd *pfd) { // Client died goto done; } - is_root = cred.uid == UID_ROOT; + is_root = cred.uid == AID_ROOT; is_zygote = cred.context == "u:r:zygote:s0"; if (!is_root && !is_zygote && !is_client(cred.pid)) { @@ -251,7 +251,7 @@ static void handle_request(pollfd *pfd) { } break; case MainRequest::REMOVE_MODULES: - if (!is_root && cred.uid != UID_SHELL) { + if (!is_root && cred.uid != AID_SHELL) { write_int(client, MainResponse::ACCESS_DENIED); goto done; } @@ -414,7 +414,7 @@ int connect_daemon(int req, bool create) { socklen_t len = setup_sockaddr(&sun, MAIN_SOCKET); int fd = xsocket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); if (connect(fd, (sockaddr *) &sun, len)) { - if (!create || getuid() != UID_ROOT) { + if (!create || getuid() != AID_ROOT) { LOGE("No daemon is currently running!\n"); close(fd); return -1; diff --git a/native/jni/include/daemon.hpp b/native/jni/include/daemon.hpp index 2e2654acf..1be5e7cd7 100644 --- a/native/jni/include/daemon.hpp +++ b/native/jni/include/daemon.hpp @@ -9,10 +9,15 @@ #include +#define AID_ROOT 0 +#define AID_SHELL 2000 #define AID_APP_START 10000 #define AID_APP_END 19999 #define AID_USER_OFFSET 100000 +#define to_app_id(uid) (uid % AID_USER_OFFSET) +#define to_user_id(uid) (uid / AID_USER_OFFSET) + // Daemon command codes namespace MainRequest { enum : int { diff --git a/native/jni/su/connect.cpp b/native/jni/su/connect.cpp index ea1d19cab..6a192c02a 100644 --- a/native/jni/su/connect.cpp +++ b/native/jni/su/connect.cpp @@ -5,7 +5,6 @@ #include #include "su.hpp" -#include "daemon.hpp" extern int SDK_INT; diff --git a/native/jni/su/su.cpp b/native/jni/su/su.cpp index 1afa29f85..cc9d480ea 100644 --- a/native/jni/su/su.cpp +++ b/native/jni/su/su.cpp @@ -14,7 +14,6 @@ #include #include -#include #include #include diff --git a/native/jni/su/su.hpp b/native/jni/su/su.hpp index 7542c5512..6e6ddee98 100644 --- a/native/jni/su/su.hpp +++ b/native/jni/su/su.hpp @@ -5,6 +5,7 @@ #include #include +#include #define DEFAULT_SHELL "/system/bin/sh" @@ -41,7 +42,7 @@ private: }; struct su_req_base { - int uid = UID_ROOT; + int uid = AID_ROOT; bool login = false; bool keepenv = false; bool mount_master = false; diff --git a/native/jni/su/su_daemon.cpp b/native/jni/su/su_daemon.cpp index b98b2dc6d..0aa186986 100644 --- a/native/jni/su/su_daemon.cpp +++ b/native/jni/su/su_daemon.cpp @@ -5,11 +5,9 @@ #include #include -#include #include #include #include -#include #include "su.hpp" #include "pts.hpp" @@ -88,7 +86,7 @@ void su_info::check_db() { } bool uid_granted_root(int uid) { - if (uid == UID_ROOT) + if (uid == AID_ROOT) return true; db_settings cfg; @@ -99,11 +97,11 @@ bool uid_granted_root(int uid) { case ROOT_ACCESS_DISABLED: return false; case ROOT_ACCESS_APPS_ONLY: - if (uid == UID_SHELL) + if (uid == AID_SHELL) return false; break; case ROOT_ACCESS_ADB_ONLY: - if (uid != UID_SHELL) + if (uid != AID_SHELL) return false; break; case ROOT_ACCESS_APPS_AND_ADB: @@ -186,7 +184,7 @@ static shared_ptr get_su_info(unsigned uid) { info->check_db(); // If it's root or the manager, allow it silently - if (info->uid == UID_ROOT || to_app_id(info->uid) == to_app_id(info->mgr_uid)) { + if (info->uid == AID_ROOT || to_app_id(info->uid) == to_app_id(info->mgr_uid)) { info->access = SILENT_SU_ACCESS; return info; } @@ -198,13 +196,13 @@ static shared_ptr get_su_info(unsigned uid) { info->access = NO_SU_ACCESS; break; case ROOT_ACCESS_ADB_ONLY: - if (info->uid != UID_SHELL) { + if (info->uid != AID_SHELL) { LOGW("Root access limited to ADB only!\n"); info->access = NO_SU_ACCESS; } break; case ROOT_ACCESS_APPS_ONLY: - if (info->uid == UID_SHELL) { + if (info->uid == AID_SHELL) { LOGW("Root access is disabled for ADB!\n"); info->access = NO_SU_ACCESS; }