diff --git a/activity.cpp b/activity.cpp index 0328063..a192751 100644 --- a/activity.cpp +++ b/activity.cpp @@ -110,10 +110,7 @@ int send_intent(struct su_context *ctx, const char *socket_path, int allow, int data.writeInt32(VAL_STRING); data.writeString16(String16("desired_cmd")); data.writeInt32(VAL_STRING); - if (ctx->to.command) - data.writeString16(String16(ctx->to.command)); - else - data.writeString16(String16(ctx->to.shell)); + data.writeString16(String16(get_command(&ctx->to))); data.writeInt32(VAL_STRING); data.writeString16(String16("socket")); diff --git a/db.c b/db.c index 7d192ee..07b353c 100644 --- a/db.c +++ b/db.c @@ -52,7 +52,7 @@ static int db_check(sqlite3 *db, struct su_context *ctx) sqlite3_snprintf( sizeof(sql), sql, "SELECT _id,name,allow FROM apps WHERE uid=%u AND exec_uid=%u AND exec_cmd='%q';", - ctx->from.uid, ctx->to.uid, (ctx->to.command) ? ctx->to.command : ctx->to.shell + ctx->from.uid, ctx->to.uid, get_command(&ctx->to) ); if (strlen(sql) >= sizeof(sql)-1) diff --git a/su.c b/su.c index b8ddc70..d8ed29b 100644 --- a/su.c +++ b/su.c @@ -217,7 +217,7 @@ do { \ PLOGE("write(bin)"); return -1; } - cmd = (ctx->to.command) ? ctx->to.command : ctx->to.shell; + cmd = get_command(&ctx->to); cmd_size = strlen(cmd) + 1; write_token(fd, cmd_size); len = write(fd, cmd, cmd_size); @@ -262,7 +262,7 @@ static void usage(int status) static void deny(struct su_context *ctx) { - char *cmd = (ctx->to.command) ? ctx->to.command : ctx->to.shell; + char *cmd = get_command(&ctx->to); send_intent(ctx, "", 0, 1); LOGW("request rejected (%u->%u %s)", ctx->from.uid, ctx->to.uid, cmd); @@ -306,7 +306,7 @@ static void allow(struct su_context *ctx) LOGD("%u %s executing %u %s using shell %s : %s%s%s%s%s%s%s%s%s%s%s%s%s%s", ctx->from.uid, ctx->from.bin, - ctx->to.uid, (ctx->to.command) ? ctx->to.command : ctx->to.shell, ctx->to.shell, + ctx->to.uid, get_command(&ctx->to), ctx->to.shell, arg0, PARG(0), PARG(1), PARG(2), PARG(3), PARG(4), PARG(5), (ctx->to.optind + 6 < ctx->to.argc) ? " ..." : ""); diff --git a/su.h b/su.h index f5e1970..ae51920 100644 --- a/su.h +++ b/su.h @@ -72,6 +72,11 @@ extern int database_check(struct su_context *ctx); extern int send_intent(struct su_context *ctx, const char *socket_path, int allow, int type); +static inline char *get_command(struct su_request *to) +{ + return (to->command) ? to->command : to->shell; +} + #if 0 #undef LOGE #define LOGE(fmt,args...) fprintf(stderr, fmt , ## args )