Create utility method for calculating supplemental_uid from app_uid am: b18fea1abb
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2004993 Change-Id: I91ab5fd0e4789fd21b69911bcc448a23434b0521
This commit is contained in:
commit
ecefb5a0ed
4 changed files with 31 additions and 0 deletions
|
@ -30,6 +30,7 @@ extern userid_t multiuser_get_user_id(uid_t uid);
|
|||
extern appid_t multiuser_get_app_id(uid_t uid);
|
||||
|
||||
extern uid_t multiuser_get_uid(userid_t user_id, appid_t app_id);
|
||||
extern uid_t multiuser_get_supplemental_uid(userid_t user_id, appid_t app_id);
|
||||
|
||||
extern gid_t multiuser_get_cache_gid(userid_t user_id, appid_t app_id);
|
||||
extern gid_t multiuser_get_ext_gid(userid_t user_id, appid_t app_id);
|
||||
|
|
|
@ -210,6 +210,10 @@
|
|||
*/
|
||||
#define AID_OVERFLOWUID 65534 /* unmapped user in the user namespace */
|
||||
|
||||
/* use the ranges below to determine whether a process is supplemental */
|
||||
#define AID_SUPPLEMENTAL_PROCESS_START 20000 /* start of uids allocated to supplemental process */
|
||||
#define AID_SUPPLEMENTAL_PROCESS_END 29999 /* end of uids allocated to supplemental process */
|
||||
|
||||
/* use the ranges below to determine whether a process is isolated */
|
||||
#define AID_ISOLATED_START 90000 /* start of uids for fully isolated sandboxed processes */
|
||||
#define AID_ISOLATED_END 99999 /* end of uids for fully isolated sandboxed processes */
|
||||
|
|
|
@ -29,6 +29,15 @@ uid_t multiuser_get_uid(userid_t user_id, appid_t app_id) {
|
|||
return (user_id * AID_USER_OFFSET) + (app_id % AID_USER_OFFSET);
|
||||
}
|
||||
|
||||
uid_t multiuser_get_supplemental_uid(userid_t user_id, appid_t app_id) {
|
||||
int supplementalProcessOffset = AID_SUPPLEMENTAL_PROCESS_START - AID_APP_START;
|
||||
if (app_id >= AID_APP_START && app_id <= AID_APP_END) {
|
||||
return (user_id * AID_USER_OFFSET) + (app_id % AID_USER_OFFSET) + supplementalProcessOffset;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
gid_t multiuser_get_cache_gid(userid_t user_id, appid_t app_id) {
|
||||
if (app_id >= AID_APP_START && app_id <= AID_APP_END) {
|
||||
return multiuser_get_uid(user_id, (app_id - AID_APP_START) + AID_CACHE_GID_START);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
static constexpr auto ERR_GID = static_cast<gid_t>(-1);
|
||||
static constexpr auto ERR_UID = static_cast<uid_t>(-1);
|
||||
|
||||
TEST(MultiuserTest, TestMerge) {
|
||||
EXPECT_EQ(0U, multiuser_get_uid(0, 0));
|
||||
|
@ -30,6 +31,22 @@ TEST(MultiuserTest, TestMerge) {
|
|||
EXPECT_EQ(1050000U, multiuser_get_uid(10, 50000));
|
||||
}
|
||||
|
||||
TEST(MultiuserTest, TestSupplementalUid) {
|
||||
EXPECT_EQ(ERR_UID, multiuser_get_supplemental_uid(0, 0));
|
||||
EXPECT_EQ(ERR_UID, multiuser_get_supplemental_uid(0, 1000));
|
||||
EXPECT_EQ(20000U, multiuser_get_supplemental_uid(0, 10000));
|
||||
EXPECT_EQ(25000U, multiuser_get_supplemental_uid(0, 15000));
|
||||
EXPECT_EQ(29999U, multiuser_get_supplemental_uid(0, 19999));
|
||||
EXPECT_EQ(ERR_UID, multiuser_get_supplemental_uid(0, 50000));
|
||||
|
||||
EXPECT_EQ(ERR_UID, multiuser_get_supplemental_uid(10, 0));
|
||||
EXPECT_EQ(ERR_UID, multiuser_get_supplemental_uid(10, 1000));
|
||||
EXPECT_EQ(1020000U, multiuser_get_supplemental_uid(10, 10000));
|
||||
EXPECT_EQ(1025000U, multiuser_get_supplemental_uid(10, 15000));
|
||||
EXPECT_EQ(ERR_UID, multiuser_get_supplemental_uid(10, 20000));
|
||||
EXPECT_EQ(ERR_UID, multiuser_get_supplemental_uid(10, 50000));
|
||||
}
|
||||
|
||||
TEST(MultiuserTest, TestSplitUser) {
|
||||
EXPECT_EQ(0U, multiuser_get_user_id(0));
|
||||
EXPECT_EQ(0U, multiuser_get_user_id(1000));
|
||||
|
|
Loading…
Reference in a new issue