From 54827cacb9c9b65af5b35d7adabbb30fbc8ac8ee Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 24 Jan 2017 14:17:57 +0800 Subject: [PATCH] Improve communication with app --- activity.c | 43 +++++++++++++++++-------------------------- daemon.c | 2 +- su.c | 23 +++-------------------- su.h | 2 -- 4 files changed, 21 insertions(+), 49 deletions(-) diff --git a/activity.c b/activity.c index a3ef9c7d8..766fe42f1 100644 --- a/activity.c +++ b/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), diff --git a/daemon.c b/daemon.c index c94f6499a..a4e7dd596 100644 --- a/daemon.c +++ b/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"); diff --git a/su.c b/su.c index ffd2d51ad..b60dac9b0 100644 --- a/su.c +++ b/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++; } diff --git a/su.h b/su.h index 53c344824..70ba08400 100644 --- a/su.h +++ b/su.h @@ -86,14 +86,12 @@ struct su_initiator { pid_t pid; unsigned uid; unsigned user; - char name[64]; char bin[PATH_MAX]; char args[4096]; }; struct su_request { unsigned uid; - char name[64]; int login; int keepenv; char *shell;