mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-10-15 18:10:23 +00:00
Modernize database code
This commit is contained in:
@@ -42,7 +42,7 @@ static void silent_run(const char *args[]) {
|
||||
}
|
||||
|
||||
static void setup_user(char *user, struct su_info *info) {
|
||||
switch (DB_SET(info, SU_MULTIUSER_MODE)) {
|
||||
switch (info->cfg[SU_MULTIUSER_MODE]) {
|
||||
case MULTIUSER_MODE_OWNER_ONLY:
|
||||
case MULTIUSER_MODE_OWNER_MANAGED:
|
||||
sprintf(user, "%d", 0);
|
||||
@@ -59,7 +59,7 @@ void app_log(struct su_context *ctx) {
|
||||
|
||||
char fromUid[8];
|
||||
sprintf(fromUid, "%d",
|
||||
DB_SET(ctx->info, SU_MULTIUSER_MODE) == MULTIUSER_MODE_OWNER_MANAGED ?
|
||||
ctx->info->cfg[SU_MULTIUSER_MODE] == MULTIUSER_MODE_OWNER_MANAGED ?
|
||||
ctx->info->uid % 100000 : ctx->info->uid);
|
||||
|
||||
char toUid[8];
|
||||
@@ -74,7 +74,7 @@ void app_log(struct su_context *ctx) {
|
||||
const char *cmd[] = {
|
||||
AM_PATH, "broadcast",
|
||||
"-a", "android.intent.action.BOOT_COMPLETED",
|
||||
"-p", DB_STR(ctx->info, SU_MANAGER),
|
||||
"-p", ctx->info->str[SU_MANAGER],
|
||||
"-f", "0x00000020",
|
||||
"--user", user,
|
||||
"--es", "action", "log",
|
||||
@@ -95,7 +95,7 @@ void app_notify(struct su_context *ctx) {
|
||||
|
||||
char fromUid[8];
|
||||
sprintf(fromUid, "%d",
|
||||
DB_SET(ctx->info, SU_MULTIUSER_MODE) == MULTIUSER_MODE_OWNER_MANAGED ?
|
||||
ctx->info->cfg[SU_MULTIUSER_MODE] == MULTIUSER_MODE_OWNER_MANAGED ?
|
||||
ctx->info->uid % 100000 : ctx->info->uid);
|
||||
|
||||
char policy[2];
|
||||
@@ -104,7 +104,7 @@ void app_notify(struct su_context *ctx) {
|
||||
const char *cmd[] = {
|
||||
AM_PATH, "broadcast",
|
||||
"-a", "android.intent.action.BOOT_COMPLETED",
|
||||
"-p", DB_STR(ctx->info, SU_MANAGER),
|
||||
"-p", ctx->info->str[SU_MANAGER],
|
||||
"-f", "0x00000020",
|
||||
"--user", user,
|
||||
"--es", "action", "notify",
|
||||
@@ -121,7 +121,7 @@ void app_connect(const char *socket, struct su_info *info) {
|
||||
const char *cmd[] = {
|
||||
AM_PATH, "broadcast",
|
||||
"-a", "android.intent.action.BOOT_COMPLETED",
|
||||
"-p", DB_STR(info, SU_MANAGER),
|
||||
"-p", info->str[SU_MANAGER],
|
||||
"-f", "0x00000020",
|
||||
"--user", user,
|
||||
"--es", "action", "request",
|
||||
|
@@ -23,7 +23,7 @@ public:
|
||||
int count; /* Just a count for debugging purpose */
|
||||
|
||||
/* These values should be guarded with internal lock */
|
||||
struct db_settings dbs;
|
||||
struct db_settings cfg;
|
||||
struct db_strings str;
|
||||
struct su_access access;
|
||||
struct stat mgr_st;
|
||||
@@ -41,9 +41,6 @@ private:
|
||||
pthread_mutex_t _lock; /* Internal lock */
|
||||
};
|
||||
|
||||
#define DB_SET(i, e) (i)->dbs.v[e]
|
||||
#define DB_STR(i, e) (i)->str.s[e]
|
||||
|
||||
struct su_req_base {
|
||||
unsigned uid;
|
||||
bool login;
|
||||
|
@@ -62,11 +62,11 @@ static void database_check(su_info *info) {
|
||||
int uid = info->uid;
|
||||
sqlite3 *db = get_magiskdb();
|
||||
if (db) {
|
||||
get_db_settings(db, -1, &info->dbs);
|
||||
get_db_strings(db, -1, &info->str);
|
||||
get_db_settings(db, &info->cfg);
|
||||
get_db_strings(db, &info->str);
|
||||
|
||||
// Check multiuser settings
|
||||
switch (DB_SET(info, SU_MULTIUSER_MODE)) {
|
||||
switch (info->cfg[SU_MULTIUSER_MODE]) {
|
||||
case MULTIUSER_MODE_OWNER_ONLY:
|
||||
if (info->uid / 100000) {
|
||||
uid = -1;
|
||||
@@ -88,7 +88,7 @@ static void database_check(su_info *info) {
|
||||
|
||||
// We need to check our manager
|
||||
if (info->access.log || info->access.notify)
|
||||
validate_manager(DB_STR(info, SU_MANAGER), uid / 100000, &info->mgr_st);
|
||||
validate_manager(info->str[SU_MANAGER], uid / 100000, &info->mgr_st);
|
||||
}
|
||||
|
||||
static struct su_info *get_su_info(unsigned uid) {
|
||||
@@ -128,7 +128,7 @@ static struct su_info *get_su_info(unsigned uid) {
|
||||
database_check(info);
|
||||
|
||||
// Check su access settings
|
||||
switch (DB_SET(info, ROOT_ACCESS)) {
|
||||
switch (info->cfg[ROOT_ACCESS]) {
|
||||
case ROOT_ACCESS_DISABLED:
|
||||
LOGW("Root access is disabled!\n");
|
||||
info->access = NO_SU_ACCESS;
|
||||
@@ -159,7 +159,7 @@ static struct su_info *get_su_info(unsigned uid) {
|
||||
info->access = SILENT_SU_ACCESS;
|
||||
|
||||
// If still not determined, check if manager exists
|
||||
if (info->access.policy == QUERY && DB_STR(info, SU_MANAGER)[0] == '\0')
|
||||
if (info->access.policy == QUERY && info->str[SU_MANAGER][0] == '\0')
|
||||
info->access = NO_SU_ACCESS;
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ void su_daemon_handler(int client, struct ucred *credential) {
|
||||
su_info *info = get_su_info(credential->uid);
|
||||
|
||||
// Fail fast
|
||||
if (info->access.policy == DENY && DB_STR(info, SU_MANAGER)[0] == '\0') {
|
||||
if (info->access.policy == DENY && info->str[SU_MANAGER][0] == '\0') {
|
||||
LOGD("su: fast deny\n");
|
||||
write_int(client, DENY);
|
||||
close(client);
|
||||
@@ -347,8 +347,8 @@ void su_daemon_handler(int client, struct ucred *credential) {
|
||||
|
||||
// Handle namespaces
|
||||
if (ctx.req.mount_master)
|
||||
DB_SET(info, SU_MNT_NS) = NAMESPACE_MODE_GLOBAL;
|
||||
switch (DB_SET(info, SU_MNT_NS)) {
|
||||
info->cfg[SU_MNT_NS] = NAMESPACE_MODE_GLOBAL;
|
||||
switch (info->cfg[SU_MNT_NS]) {
|
||||
case NAMESPACE_MODE_GLOBAL:
|
||||
LOGD("su: use global namespace\n");
|
||||
break;
|
||||
|
Reference in New Issue
Block a user