Modernize database code

This commit is contained in:
topjohnwu
2018-11-04 18:24:08 -05:00
parent 5e4d2dedbe
commit 0742901cd2
7 changed files with 121 additions and 62 deletions

View File

@ -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;