Prune unused UIDs from su policies

This commit is contained in:
topjohnwu
2022-05-18 01:55:58 -07:00
parent e11508f84d
commit 975b1a5e36
12 changed files with 165 additions and 80 deletions

View File

@@ -359,48 +359,6 @@ int get_db_strings(db_strings &str, int key) {
return 0;
}
bool get_manager(int user_id, std::string *pkg, struct stat *st) {
db_strings str;
get_db_strings(str, SU_MANAGER);
char app_path[128];
if (!str[SU_MANAGER].empty()) {
// App is repackaged
sprintf(app_path, "%s/%d/%s", APP_DATA_DIR, user_id, str[SU_MANAGER].data());
if (stat(app_path, st) == 0) {
if (pkg)
pkg->swap(str[SU_MANAGER]);
return true;
}
}
// Check the official package name
sprintf(app_path, "%s/%d/" JAVA_PACKAGE_NAME, APP_DATA_DIR, user_id);
if (stat(app_path, st) == 0) {
if (pkg)
*pkg = JAVA_PACKAGE_NAME;
return true;
} else {
LOGE("su: cannot find manager\n");
memset(st, 0, sizeof(*st));
if (pkg)
pkg->clear();
return false;
}
}
bool get_manager(string *pkg) {
struct stat st;
return get_manager(0, pkg, &st);
}
int get_manager_app_id() {
struct stat st;
if (get_manager(0, nullptr, &st))
return to_app_id(st.st_uid);
return -1;
}
void exec_sql(int client) {
run_finally f([=]{ close(client); });
string sql = read_string(client);