Always return /vendor/bin/sh as shell for OEM ids in getpwnam() etc.

During the review of the script that generates /vendor/etc/passwd, it
was suggested that the shell be /vendor/bin/sh instead of the typical
/system/bin/sh.  This has subsequently caused bionic unit tests to
fail, since they always check that the shell is set to /system/bin/sh.

In the spirit of that review, libc is modified to return
/vendor/bin/sh for the OEM AID ranges and the test is updated to
expect this.

Test: bionic unit tests
Change-Id: Ie7c1c48fde8a71b3df1aa0ef112d42ab7bd3baec
This commit is contained in:
Tom Cherry 2018-09-27 13:19:02 -07:00 committed by Elliott Hughes
parent 8d11bea6c5
commit fa5f61c8d9
2 changed files with 16 additions and 10 deletions

View File

@ -435,7 +435,7 @@ static passwd* oem_id_to_passwd(uid_t uid, passwd_state_t* state) {
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");
snprintf(state->sh_buffer_, sizeof(state->sh_buffer_), "/vendor/bin/sh");
passwd* pw = &state->passwd_;
pw->pw_name = state->name_buffer_;

View File

@ -42,8 +42,9 @@ using android::base::Split;
using android::base::StartsWith;
enum uid_type_t {
TYPE_APP,
TYPE_SYSTEM,
TYPE_APP
TYPE_VENDOR,
};
#if defined(__BIONIC__)
@ -61,12 +62,17 @@ static void check_passwd(const passwd* pwd, const char* username, uid_t uid, uid
EXPECT_EQ(nullptr, pwd->pw_gecos);
#endif
if (uid_type == TYPE_SYSTEM) {
EXPECT_STREQ("/", pwd->pw_dir);
} else {
if (uid_type == TYPE_APP) {
EXPECT_STREQ("/data", pwd->pw_dir);
} else {
EXPECT_STREQ("/", pwd->pw_dir);
}
if (uid_type == TYPE_VENDOR) {
EXPECT_STREQ("/vendor/bin/sh", pwd->pw_shell);
} else {
EXPECT_STREQ("/system/bin/sh", pwd->pw_shell);
}
EXPECT_STREQ("/system/bin/sh", pwd->pw_shell);
}
static void check_getpwuid(const char* username, uid_t uid, uid_type_t uid_type,
@ -155,19 +161,19 @@ TEST(pwd, getpwnam_app_id_radio) {
}
TEST(pwd, getpwnam_oem_id_5000) {
check_get_passwd("oem_5000", 5000, TYPE_SYSTEM, false);
check_get_passwd("oem_5000", 5000, TYPE_VENDOR, false);
}
TEST(pwd, getpwnam_oem_id_5999) {
check_get_passwd("oem_5999", 5999, TYPE_SYSTEM, false);
check_get_passwd("oem_5999", 5999, TYPE_VENDOR, false);
}
TEST(pwd, getpwnam_oem_id_2900) {
check_get_passwd("oem_2900", 2900, TYPE_SYSTEM, false);
check_get_passwd("oem_2900", 2900, TYPE_VENDOR, false);
}
TEST(pwd, getpwnam_oem_id_2999) {
check_get_passwd("oem_2999", 2999, TYPE_SYSTEM, false);
check_get_passwd("oem_2999", 2999, TYPE_VENDOR, false);
}
TEST(pwd, getpwnam_app_id_nobody) {