mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-29 05:17:39 +00:00
Improve communication with app
This commit is contained in:
parent
e3a4a16507
commit
54827cacb9
43
activity.c
43
activity.c
@ -87,8 +87,11 @@ int send_result(struct su_context *ctx, policy_t policy) {
|
||||
char uid[256];
|
||||
sprintf(uid, "%d", ctx->from.uid);
|
||||
|
||||
char desired_uid[256];
|
||||
sprintf(desired_uid, "%d", ctx->to.uid);
|
||||
char toUid[256];
|
||||
sprintf(toUid, "%d", ctx->to.uid);
|
||||
|
||||
char pid[256];
|
||||
sprintf(pid, "%d", ctx->from.pid);
|
||||
|
||||
char user[64];
|
||||
get_owner_login_user_args(ctx, user, sizeof(user));
|
||||
@ -101,20 +104,14 @@ int send_result(struct su_context *ctx, policy_t policy) {
|
||||
AM_PATH,
|
||||
ACTION_RESULT,
|
||||
"--ei",
|
||||
"binary_version",
|
||||
binary_version,
|
||||
"--es",
|
||||
"from_name",
|
||||
ctx->from.name,
|
||||
"--es",
|
||||
"desired_name",
|
||||
ctx->to.name,
|
||||
"--ei",
|
||||
"uid",
|
||||
"from.uid",
|
||||
uid,
|
||||
"--ei",
|
||||
"desired_uid",
|
||||
desired_uid,
|
||||
"to.uid",
|
||||
toUid,
|
||||
"--ei",
|
||||
"pid",
|
||||
pid,
|
||||
"--es",
|
||||
"command",
|
||||
get_command(&ctx->to),
|
||||
@ -132,20 +129,14 @@ int send_result(struct su_context *ctx, policy_t policy) {
|
||||
AM_PATH,
|
||||
ACTION_RESULT,
|
||||
"--ei",
|
||||
"binary_version",
|
||||
binary_version,
|
||||
"--es",
|
||||
"from_name",
|
||||
ctx->from.name,
|
||||
"--es",
|
||||
"desired_name",
|
||||
ctx->to.name,
|
||||
"--ei",
|
||||
"uid",
|
||||
"from.uid",
|
||||
uid,
|
||||
"--ei",
|
||||
"desired_uid",
|
||||
desired_uid,
|
||||
"to.uid",
|
||||
toUid,
|
||||
"--ei",
|
||||
"pid",
|
||||
pid,
|
||||
"--es",
|
||||
"command",
|
||||
get_command(&ctx->to),
|
||||
|
2
daemon.c
2
daemon.c
@ -289,7 +289,7 @@ static int daemon_accept(int fd) {
|
||||
LOGD("remote req pid: %d", daemon_from_pid);
|
||||
|
||||
struct ucred credentials;
|
||||
int ucred_length = sizeof(struct ucred);
|
||||
socklen_t ucred_length = sizeof(struct ucred);
|
||||
/* fill in the user data structure */
|
||||
if(getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &credentials, &ucred_length)) {
|
||||
LOGE("could obtain credentials from unix domain socket");
|
||||
|
23
su.c
23
su.c
@ -198,12 +198,6 @@ static int from_init(struct su_initiator *from) {
|
||||
strncpy(from->bin, argv0, sizeof(from->bin));
|
||||
from->bin[sizeof(from->bin)-1] = '\0';
|
||||
|
||||
struct passwd *pw;
|
||||
pw = getpwuid(from->uid);
|
||||
if (pw && pw->pw_name) {
|
||||
strncpy(from->name, pw->pw_name, sizeof(from->name));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -417,16 +411,9 @@ do { \
|
||||
} while (0)
|
||||
|
||||
static int socket_send_request(int fd, const struct su_context *ctx) {
|
||||
write_token(fd, "version", PROTO_VERSION);
|
||||
write_token(fd, "binary.version", VERSION_CODE);
|
||||
write_token(fd, "pid", ctx->from.pid);
|
||||
write_string_data(fd, "from.name", ctx->from.name);
|
||||
write_string_data(fd, "to.name", ctx->to.name);
|
||||
write_token(fd, "from.uid", ctx->from.uid);
|
||||
write_token(fd, "to.uid", ctx->to.uid);
|
||||
write_string_data(fd, "from.bin", ctx->from.bin);
|
||||
// TODO: Fix issue where not using -c does not result a in a command
|
||||
write_string_data(fd, "command", get_command(&ctx->to));
|
||||
write_string_data(fd, "version", VERSION);
|
||||
write_token(fd, "versionCode", VERSION_CODE);
|
||||
write_token(fd, "uid", ctx->from.uid);
|
||||
write_token(fd, "eof", PROTO_VERSION);
|
||||
return 0;
|
||||
}
|
||||
@ -683,7 +670,6 @@ int su_main_nodaemon(int argc, char **argv) {
|
||||
.uid = 0,
|
||||
.bin = "",
|
||||
.args = "",
|
||||
.name = "",
|
||||
},
|
||||
.to = {
|
||||
.uid = AID_ROOT,
|
||||
@ -695,7 +681,6 @@ int su_main_nodaemon(int argc, char **argv) {
|
||||
.argv = argv,
|
||||
.argc = argc,
|
||||
.optind = 0,
|
||||
.name = "",
|
||||
},
|
||||
.user = {
|
||||
.android_user_id = 0,
|
||||
@ -791,8 +776,6 @@ int su_main_nodaemon(int argc, char **argv) {
|
||||
}
|
||||
} else {
|
||||
ctx.to.uid = pw->pw_uid;
|
||||
if (pw->pw_name)
|
||||
strncpy(ctx.to.name, pw->pw_name, sizeof(ctx.to.name));
|
||||
}
|
||||
optind++;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user