mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-12 12:03:45 +00:00
Use SQLite's internal time function
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user