diff options
author | Dianne Hackborn <hackbod@google.com> | 2012-02-09 16:14:28 -0800 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2012-02-09 16:14:28 -0800 |
commit | 058d6d88b959efc00d7ba9777e447bc55c409569 (patch) | |
tree | 267905681e7975a066a9ba4682f583a2747e001b | |
parent | 1625c7a837d73b6729f97edb32c497d289c0220c (diff) | |
download | android_bionic-058d6d88b959efc00d7ba9777e447bc55c409569.tar.gz android_bionic-058d6d88b959efc00d7ba9777e447bc55c409569.tar.bz2 android_bionic-058d6d88b959efc00d7ba9777e447bc55c409569.zip |
Update bionic to know users and isolated uids for uid string representation.
Change-Id: I6681bacd69299a7f9837ef8025a80c5562081bad
-rw-r--r-- | libc/bionic/stubs.c | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/libc/bionic/stubs.c b/libc/bionic/stubs.c index 5f6342722..cc4c04ec3 100644 --- a/libc/bionic/stubs.c +++ b/libc/bionic/stubs.c @@ -250,30 +250,58 @@ android_name_to_group( struct group *gr, const char *name ) static unsigned app_id_from_name( const char* name ) { - unsigned long id; + unsigned long userid; + unsigned long appid; char* end; - if (memcmp(name, "app_", 4) != 0 || !isdigit(name[4])) + if (name[0] != 'u' || !isdigit(name[1])) goto FAIL; - id = strtoul(name+4, &end, 10); - if (*end != '\0') + userid = strtoul(name+1, &end, 10); + if (end[0] != '_' || end[1] == 0 || !isdigit(end[2])) goto FAIL; - id += AID_APP; + if (end[1] == 'a') + appid = strtoul(end+2, &end, 10) + AID_APP; + else if (end[1] == 'i') + appid = strtoul(end+2, &end, 10) + AID_ISOLATED_START; + else + goto FAIL; + + if (end[0] != 0) + goto FAIL; - /* check for overflow and that the value can be - * stored in our 32-bit uid_t/gid_t */ - if (id < AID_APP || (unsigned)id != id) + /* check that user id won't overflow */ + if (userid > 1000) goto FAIL; - return (unsigned)id; + /* check that app id is within range */ + if (appid < AID_APP || appid >= AID_USER) + goto FAIL; + + return (unsigned)(appid + userid*AID_USER); FAIL: errno = ENOENT; return 0; } +static void +print_app_uid_name(uid_t uid, char* buffer, int bufferlen) +{ + uid_t appid; + uid_t userid; + + appid = uid % AID_USER; + userid = uid / AID_USER; + + if (appid < AID_ISOLATED_START) { + snprintf(buffer, bufferlen, "u%u_a%u", userid, appid - AID_APP); + } else { + snprintf(buffer, bufferlen, "u%u_i%u", userid, appid - AID_ISOLATED_START); + } +} + /* translate a uid into the corresponding app_<uid> * passwd structure (sets errno to ENOENT on failure) */ @@ -287,8 +315,7 @@ app_id_to_passwd(uid_t uid, stubs_state_t* state) return NULL; } - snprintf( state->app_name_buffer, sizeof state->app_name_buffer, - "app_%u", uid - AID_APP ); + print_app_uid_name(uid, state->app_name_buffer, sizeof state->app_name_buffer); pw->pw_name = state->app_name_buffer; pw->pw_dir = "/data"; @@ -306,14 +333,15 @@ static struct group* app_id_to_group(gid_t gid, stubs_state_t* state) { struct group* gr = &state->group; + int appid; + int userid; if (gid < AID_APP) { errno = ENOENT; return NULL; } - snprintf(state->group_name_buffer, sizeof state->group_name_buffer, - "app_%u", gid - AID_APP); + print_app_uid_name(gid, state->group_name_buffer, sizeof state->group_name_buffer); gr->gr_name = state->group_name_buffer; gr->gr_gid = gid; |