Detect package name for copying binaries

Close #2152
This commit is contained in:
topjohnwu
2019-12-17 16:38:12 -05:00
parent 06c42d05c3
commit 695c8bc5d0
3 changed files with 33 additions and 19 deletions
+20 -7
View File
@@ -246,28 +246,41 @@ int get_uid_policy(su_access &su, int uid) {
return 0;
}
int validate_manager(string &alt_pkg, int userid, struct stat *st) {
bool check_manager(string *pkg) {
db_strings str;
get_db_strings(str, SU_MANAGER);
bool ret = validate_manager(str[SU_MANAGER], 0, nullptr);
if (pkg) {
if (ret)
pkg->swap(str[SU_MANAGER]);
else
*pkg = "xxx"; /* Make sure the return pkg can never exist */
}
return ret;
}
bool validate_manager(string &pkg, int userid, struct stat *st) {
struct stat tmp_st;
if (st == nullptr)
st = &tmp_st;
// Prefer DE storage
char app_path[128];
sprintf(app_path, "%s/%d/%s", APP_DATA_DIR, userid, alt_pkg.empty() ? "xxx" : alt_pkg.data());
if (stat(app_path, st)) {
sprintf(app_path, "%s/%d/%s", APP_DATA_DIR, userid, pkg.data());
if (pkg.empty() || stat(app_path, st)) {
// Check the official package name
sprintf(app_path, "%s/%d/" JAVA_PACKAGE_NAME, APP_DATA_DIR, userid);
if (stat(app_path, st)) {
LOGE("su: cannot find manager");
memset(st, 0, sizeof(*st));
alt_pkg.clear();
return 1;
pkg.clear();
return false;
} else {
// Switch to official package if exists
alt_pkg = JAVA_PACKAGE_NAME;
pkg = JAVA_PACKAGE_NAME;
}
}
return 0;
return true;
}
void exec_sql(int client) {