mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-22 16:07:39 +00:00
Move su request path to magisk tmp
This commit is contained in:
parent
2359cfc480
commit
9929b25339
@ -13,6 +13,7 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.DataOutputStream
|
import java.io.DataOutputStream
|
||||||
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
@ -22,7 +23,7 @@ class SuRequestHandler(
|
|||||||
private val policyDB: PolicyDao
|
private val policyDB: PolicyDao
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private lateinit var output: DataOutputStream
|
private lateinit var output: File
|
||||||
private lateinit var policy: SuPolicy
|
private lateinit var policy: SuPolicy
|
||||||
lateinit var pkgInfo: PackageInfo
|
lateinit var pkgInfo: PackageInfo
|
||||||
private set
|
private set
|
||||||
@ -52,42 +53,27 @@ class SuRequestHandler(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun close() {
|
|
||||||
if (::output.isInitialized)
|
|
||||||
runCatching { output.close() }
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun init(intent: Intent): Boolean {
|
private suspend fun init(intent: Intent): Boolean {
|
||||||
val uid = intent.getIntExtra("uid", -1)
|
val uid = intent.getIntExtra("uid", -1)
|
||||||
if (uid <= 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
policy = SuPolicy(uid)
|
|
||||||
val pid = intent.getIntExtra("pid", -1)
|
val pid = intent.getIntExtra("pid", -1)
|
||||||
if (pid <= 0) {
|
val fifo = intent.getStringExtra("fifo")
|
||||||
return false;
|
if (uid <= 0 || pid <= 0 || fifo == null) {
|
||||||
}
|
|
||||||
val fifo = intent.getStringExtra("fifo") ?: "/dev/socket/magisk_su_request_$pid"
|
|
||||||
|
|
||||||
try {
|
|
||||||
output = DataOutputStream(FileOutputStream(fifo))
|
|
||||||
try {
|
|
||||||
pkgInfo = pm.getPackageInfo(uid, pid) ?: PackageInfo().apply {
|
|
||||||
val name = pm.getNameForUid(uid) ?: throw PackageManager.NameNotFoundException()
|
|
||||||
// We only fill in sharedUserId and leave other fields uninitialized
|
|
||||||
sharedUserId = name.split(":")[0]
|
|
||||||
}
|
|
||||||
} catch (e: PackageManager.NameNotFoundException) {
|
|
||||||
Timber.e(e)
|
|
||||||
respond(SuPolicy.DENY, -1)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
} catch (e: IOException) {
|
|
||||||
Timber.e(e)
|
|
||||||
close()
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
output = File(fifo)
|
||||||
|
policy = SuPolicy(uid)
|
||||||
|
try {
|
||||||
|
pkgInfo = pm.getPackageInfo(uid, pid) ?: PackageInfo().apply {
|
||||||
|
val name = pm.getNameForUid(uid) ?: throw PackageManager.NameNotFoundException()
|
||||||
|
// We only fill in sharedUserId and leave other fields uninitialized
|
||||||
|
sharedUserId = name.split(":")[0]
|
||||||
|
}
|
||||||
|
} catch (e: PackageManager.NameNotFoundException) {
|
||||||
|
Timber.e(e)
|
||||||
|
respond(SuPolicy.DENY, -1)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return output.canWrite()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun respond(action: Int, time: Int) {
|
suspend fun respond(action: Int, time: Int) {
|
||||||
@ -102,14 +88,15 @@ class SuRequestHandler(
|
|||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
output.writeInt(policy.policy)
|
DataOutputStream(FileOutputStream(output)).use {
|
||||||
output.flush()
|
it.writeInt(policy.policy)
|
||||||
|
it.flush()
|
||||||
|
}
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
Timber.e(e)
|
Timber.e(e)
|
||||||
} finally {
|
}
|
||||||
close()
|
if (until >= 0) {
|
||||||
if (until >= 0)
|
policyDB.update(policy)
|
||||||
policyDB.update(policy)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,10 @@
|
|||||||
|
|
||||||
#include <base.hpp>
|
#include <base.hpp>
|
||||||
#include <selinux.hpp>
|
#include <selinux.hpp>
|
||||||
|
#include <magisk.hpp>
|
||||||
|
|
||||||
#include "su.hpp"
|
#include "su.hpp"
|
||||||
|
|
||||||
extern int SDK_INT;
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#define CALL_PROVIDER \
|
#define CALL_PROVIDER \
|
||||||
@ -193,14 +192,15 @@ void app_notify(const su_context &ctx) {
|
|||||||
int app_request(const su_context &ctx) {
|
int app_request(const su_context &ctx) {
|
||||||
// Create FIFO
|
// Create FIFO
|
||||||
char fifo[64];
|
char fifo[64];
|
||||||
ssprintf(fifo, sizeof(fifo), "/dev/socket/magisk_su_request_%d", ctx.pid);
|
ssprintf(fifo, sizeof(fifo), "%s/" INTLROOT "/su_request_%d", MAGISKTMP.data(), ctx.pid);
|
||||||
mkfifo(fifo, 0600);
|
mkfifo(fifo, 0600);
|
||||||
chown(fifo, ctx.info->mgr_uid, ctx.info->mgr_uid);
|
chown(fifo, ctx.info->mgr_uid, ctx.info->mgr_uid);
|
||||||
setfilecon(fifo, MAGISK_FILE_CON);
|
setfilecon(fifo, MAGISK_FILE_CON);
|
||||||
|
|
||||||
// Send request
|
// Send request
|
||||||
vector<Extra> extras;
|
vector<Extra> extras;
|
||||||
extras.reserve(2);
|
extras.reserve(3);
|
||||||
|
extras.emplace_back("fifo", fifo);
|
||||||
extras.emplace_back("uid", ctx.info->eval_uid);
|
extras.emplace_back("uid", ctx.info->eval_uid);
|
||||||
extras.emplace_back("pid", ctx.pid);
|
extras.emplace_back("pid", ctx.pid);
|
||||||
exec_cmd("request", extras, ctx.info, false);
|
exec_cmd("request", extras, ctx.info, false);
|
||||||
|
@ -265,7 +265,7 @@ void MagiskInit::setup_tmp(const char *path) {
|
|||||||
LOGD("Setup Magisk tmp at %s\n", path);
|
LOGD("Setup Magisk tmp at %s\n", path);
|
||||||
chdir("/data");
|
chdir("/data");
|
||||||
|
|
||||||
xmkdir(INTLROOT, 0755);
|
xmkdir(INTLROOT, 0711);
|
||||||
xmkdir(MIRRDIR, 0);
|
xmkdir(MIRRDIR, 0);
|
||||||
xmkdir(BLOCKDIR, 0);
|
xmkdir(BLOCKDIR, 0);
|
||||||
xmkdir(WORKERDIR, 0);
|
xmkdir(WORKERDIR, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user