Cleanup database code

This commit is contained in:
topjohnwu
2025-01-04 02:24:08 -08:00
committed by John Wu
parent 10e47248de
commit 3ca6d06f69
7 changed files with 231 additions and 214 deletions
+7 -7
View File
@@ -67,7 +67,7 @@ void su_info::check_db() {
ssprintf(query, sizeof(query),
"SELECT policy, logging, notification FROM policies "
"WHERE uid=%d AND (until=0 OR until>%li)", eval_uid, time(nullptr));
auto res = db_exec(query, [&](db_row &row) -> bool {
bool res = db_exec(query, [&](db_row &row) -> bool {
access.policy = (policy_t) parse_int(row["policy"]);
access.log = parse_int(row["logging"]);
access.notify = parse_int(row["notification"]);
@@ -75,7 +75,7 @@ void su_info::check_db() {
access.policy, access.log, access.notify);
return true;
});
if (res.check_err())
if (!res)
return;
}
@@ -128,11 +128,11 @@ bool uid_granted_root(int uid) {
ssprintf(query, sizeof(query),
"SELECT policy FROM policies WHERE uid=%d AND (until=0 OR until>%li)",
uid, time(nullptr));
auto res = db_exec(query, [&](db_row &row) -> bool {
bool res = db_exec(query, [&](db_row &row) -> bool {
granted = parse_int(row["policy"]) == ALLOW;
return true;
});
if (res.check_err())
if (!res)
return false;
return granted;
@@ -142,7 +142,7 @@ void prune_su_access() {
cached.reset();
vector<bool> app_no_list = get_app_no_list();
vector<int> rm_uids;
auto res = db_exec("SELECT uid FROM policies", [&](db_row &row) -> bool {
bool res = db_exec("SELECT uid FROM policies", [&](db_row &row) -> bool {
int uid = parse_int(row["uid"]);
int app_id = to_app_id(uid);
if (app_id >= AID_APP_START && app_id <= AID_APP_END) {
@@ -154,13 +154,13 @@ void prune_su_access() {
}
return true;
});
if (res.check_err())
if (!res)
return;
for (int uid : rm_uids) {
char query[256];
ssprintf(query, sizeof(query), "DELETE FROM policies WHERE uid == %d", uid);
db_exec(query).check_err();
db_exec(query);
}
}