fix oem_XXXX ids to incorporate both ranges

The XXXX now lines up to the underlying uid and has no offset.
Work with AID_OEM_RESERVED uids.

Test uses hard coded values to catch changes in the API expectations
that may occur in private/android_filesystem_config.h.

SideEffects: names change, some product dependencies.

Bug: 27999086
Change-Id: Ic2b4c36de74ae009a44e14711c75834293828207
This commit is contained in:
Mark Salyzyn 2016-04-05 09:24:59 -07:00
parent 9deb01c5a6
commit 8d387ee1ec
2 changed files with 40 additions and 17 deletions

View File

@ -312,27 +312,34 @@ static void print_app_name_from_gid(const gid_t gid, char* buffer, const int buf
}
}
// oem_XXXX -> uid
// Supported ranges:
// AID_OEM_RESERVED_START to AID_OEM_RESERVED_END (2900-2999)
// AID_OEM_RESERVED_2_START to AID_OEM_RESERVED_2_END (5000-5999)
// Check OEM id is within range.
static bool is_oem_id(id_t id) {
return (((id >= AID_OEM_RESERVED_START) && (id <= AID_OEM_RESERVED_END)) ||
((id >= AID_OEM_RESERVED_2_START) && (id <= AID_OEM_RESERVED_2_END)));
}
// Translate an OEM name to the corresponding user/group id.
// oem_XXX -> AID_OEM_RESERVED_2_START + XXX, iff XXX is within range.
static id_t oem_id_from_name(const char* name) {
unsigned int id;
if (sscanf(name, "oem_%u", &id) != 1) {
return 0;
}
// Check OEM id is within range.
if (id > (AID_OEM_RESERVED_2_END - AID_OEM_RESERVED_2_START)) {
if (!is_oem_id(id)) {
return 0;
}
return AID_OEM_RESERVED_2_START + static_cast<id_t>(id);
return static_cast<id_t>(id);
}
static passwd* oem_id_to_passwd(uid_t uid, passwd_state_t* state) {
if (uid < AID_OEM_RESERVED_2_START || uid > AID_OEM_RESERVED_2_END) {
if (!is_oem_id(uid)) {
return NULL;
}
snprintf(state->name_buffer_, sizeof(state->name_buffer_), "oem_%u",
uid - AID_OEM_RESERVED_2_START);
snprintf(state->name_buffer_, sizeof(state->name_buffer_), "oem_%u", uid);
snprintf(state->dir_buffer_, sizeof(state->dir_buffer_), "/");
snprintf(state->sh_buffer_, sizeof(state->sh_buffer_), "/system/bin/sh");
@ -346,12 +353,12 @@ static passwd* oem_id_to_passwd(uid_t uid, passwd_state_t* state) {
}
static group* oem_id_to_group(gid_t gid, group_state_t* state) {
if (gid < AID_OEM_RESERVED_2_START || gid > AID_OEM_RESERVED_2_END) {
if (!is_oem_id(gid)) {
return NULL;
}
snprintf(state->group_name_buffer_, sizeof(state->group_name_buffer_),
"oem_%u", gid - AID_OEM_RESERVED_2_START);
"oem_%u", gid);
group* gr = &state->group_;
gr->gr_name = state->group_name_buffer_;

View File

@ -122,12 +122,20 @@ TEST(getpwnam, app_id_radio) {
check_get_passwd("radio", 1001, TYPE_SYSTEM);
}
TEST(getpwnam, oem_id_0) {
check_get_passwd("oem_0", 5000, TYPE_SYSTEM);
TEST(getpwnam, oem_id_5000) {
check_get_passwd("oem_5000", 5000, TYPE_SYSTEM);
}
TEST(getpwnam, oem_id_999) {
check_get_passwd("oem_999", 5999, TYPE_SYSTEM);
TEST(getpwnam, oem_id_5999) {
check_get_passwd("oem_5999", 5999, TYPE_SYSTEM);
}
TEST(getpwnam, oem_id_2900) {
check_get_passwd("oem_2900", 2900, TYPE_SYSTEM);
}
TEST(getpwnam, oem_id_2999) {
check_get_passwd("oem_2999", 2999, TYPE_SYSTEM);
}
TEST(getpwnam, app_id_nobody) {
@ -255,12 +263,20 @@ TEST(getgrnam, app_id_radio) {
check_get_group("radio", 1001);
}
TEST(getgrnam, oem_id_0) {
check_get_group("oem_0", 5000);
TEST(getgrnam, oem_id_5000) {
check_get_group("oem_5000", 5000);
}
TEST(getgrnam, oem_id_999) {
check_get_group("oem_999", 5999);
TEST(getgrnam, oem_id_5999) {
check_get_group("oem_5999", 5999);
}
TEST(getgrnam, oem_id_2900) {
check_get_group("oem_2900", 2900);
}
TEST(getgrnam, oem_id_2999) {
check_get_group("oem_2999", 2999);
}
TEST(getgrnam, app_id_nobody) {