Use SQLite's internal time function

This commit is contained in:
topjohnwu
2025-01-05 04:32:47 -08:00
committed by John Wu
parent b782e7dcb7
commit 0d31d356ef
10 changed files with 62 additions and 48 deletions

View File

@@ -2,8 +2,7 @@ use crate::daemon::MagiskD;
use crate::db::DbArg::Integer;
use crate::db::{SqlTable, SqliteResult, SqliteReturn};
use crate::ffi::{DbValues, RootSettings, SuPolicy};
use base::{libc, ResultExt};
use std::ptr;
use base::ResultExt;
impl Default for SuPolicy {
fn default() -> Self {
@@ -40,11 +39,8 @@ impl MagiskD {
fn get_root_settings(&self, uid: i32, settings: &mut RootSettings) -> SqliteResult {
self.db_exec_with_rows(
"SELECT policy, logging, notification FROM policies \
WHERE uid=? AND (until=0 OR until>?)",
&[
Integer(uid as i64),
Integer(unsafe { libc::time(ptr::null_mut()).into() }),
],
WHERE uid=? AND (until=0 OR until>strftime('%s', 'now'))",
&[Integer(uid as i64)],
settings,
)
.sql_result()

View File

@@ -111,9 +111,8 @@ bool uid_granted_root(int uid) {
}
bool granted = false;
db_exec("SELECT policy FROM policies WHERE uid=? AND (until=0 OR until>?)",
{ uid, time(nullptr) },
[&](auto, const DbValues &values) { granted = values.get_int(0) == +SuPolicy::Allow; });
db_exec("SELECT policy FROM policies WHERE uid=? AND (until=0 OR until>strftime('%s', 'now'))",
{ uid }, [&](auto, const DbValues &v) { granted = v.get_int(0) == +SuPolicy::Allow; });
return granted;
}
@@ -141,9 +140,7 @@ void prune_su_access() {
}
}
for (int uid : rm_uids) {
char query[256];
ssprintf(query, sizeof(query), "DELETE FROM policies WHERE uid == %d", uid);
db_exec(query);
db_exec("DELETE FROM policies WHERE uid=?", { uid });
}
}