From 8a05a01de75d78a45d646115b20b2a3e3c12ba9e Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Thu, 13 Sep 2012 14:31:50 -0700 Subject: [PATCH] Print out shared app gids correctly For applications that share resources across users such as forward-locked applications, print out their group name correctly. Change-Id: I06ee0b67e4325cfa415ffd7a03e301700399a66d --- libc/bionic/stubs.cpp | 19 ++++++++++--------- tests/stubs_test.cpp | 8 ++++++++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/libc/bionic/stubs.cpp b/libc/bionic/stubs.cpp index fb1a8e41f..1cab7d32f 100644 --- a/libc/bionic/stubs.cpp +++ b/libc/bionic/stubs.cpp @@ -266,18 +266,19 @@ static unsigned app_id_from_name(const char* name) { static void print_app_name_from_appid_userid(const uid_t appid, const uid_t userid, char* buffer, const int bufferlen) { - if (appid < AID_ISOLATED_START) { - if (appid < AID_APP) { - for (size_t n = 0; n < android_id_count; n++) { - if (android_ids[n].aid == appid) { - snprintf(buffer, bufferlen, "u%u_%s", userid, android_ids[n].name); - return; - } + if (appid >= AID_ISOLATED_START) { + snprintf(buffer, bufferlen, "u%u_i%u", userid, appid - AID_ISOLATED_START); + } else if (userid == 0 && appid >= AID_SHARED_GID_START) { + snprintf(buffer, bufferlen, "all_a%u", appid - AID_SHARED_GID_START); + } else if (appid < AID_APP) { + for (size_t n = 0; n < android_id_count; n++) { + if (android_ids[n].aid == appid) { + snprintf(buffer, bufferlen, "u%u_%s", userid, android_ids[n].name); + return; } } - snprintf(buffer, bufferlen, "u%u_a%u", userid, appid - AID_APP); } else { - snprintf(buffer, bufferlen, "u%u_i%u", userid, appid - AID_ISOLATED_START); + snprintf(buffer, bufferlen, "u%u_a%u", userid, appid - AID_APP); } } diff --git a/tests/stubs_test.cpp b/tests/stubs_test.cpp index 079779ef3..d2d0ad837 100644 --- a/tests/stubs_test.cpp +++ b/tests/stubs_test.cpp @@ -68,6 +68,14 @@ TEST(getpwnam, app_id_nobody) { CHECK_GETPWNAM_FOR("nobody", 9999, TYPE_SYSTEM); } +TEST(getpwnam, app_id_all_a0) { + CHECK_GETPWNAM_FOR("all_a0", 50000, TYPE_APP); +} + +TEST(getpwnam, app_id_u1_a40000) { + CHECK_GETPWNAM_FOR("u1_a40000", 150000, TYPE_APP); +} + TEST(getpwnam, app_id_u0_a0) { CHECK_GETPWNAM_FOR("u0_a0", 10000, TYPE_APP); }