diff options
author | Tom Cherry <tomcherry@google.com> | 2018-02-12 16:27:20 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-02-12 16:27:20 +0000 |
commit | ab8c86159738a774ca99a5b3311e5e3b81fc8ce9 (patch) | |
tree | a35165b08fe9fcd81d936d5a3ae2eadee6e2dc48 /libc/bionic/grp_pwd.cpp | |
parent | 4362da80760ef76af310280e70fddb6b6d3d043f (diff) | |
parent | 6034ef85d86675d063d6b1920e85e4c471b95904 (diff) | |
download | android_bionic-ab8c86159738a774ca99a5b3311e5e3b81fc8ce9.tar.gz android_bionic-ab8c86159738a774ca99a5b3311e5e3b81fc8ce9.tar.bz2 android_bionic-ab8c86159738a774ca99a5b3311e5e3b81fc8ce9.zip |
Merge "Add ability to read /etc/passwd and /etc/group"
Diffstat (limited to 'libc/bionic/grp_pwd.cpp')
-rw-r--r-- | libc/bionic/grp_pwd.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/libc/bionic/grp_pwd.cpp b/libc/bionic/grp_pwd.cpp index 43a503208..952058fef 100644 --- a/libc/bionic/grp_pwd.cpp +++ b/libc/bionic/grp_pwd.cpp @@ -44,6 +44,10 @@ // Generated android_ids array #include "generated_android_ids.h" +#include "grp_pwd_file.h" + +static PasswdFile vendor_passwd("/vendor/etc/passwd"); +static GroupFile vendor_group("/vendor/etc/group"); // POSIX seems to envisage an implementation where the <pwd.h> functions are // implemented by brute-force searching with getpwent(3), and the <grp.h> @@ -422,7 +426,11 @@ static id_t oem_id_from_name(const char* name) { static passwd* oem_id_to_passwd(uid_t uid, passwd_state_t* state) { if (!is_oem_id(uid)) { - return NULL; + return nullptr; + } + + if (vendor_passwd.FindById(uid, state)) { + return &state->passwd_; } snprintf(state->name_buffer_, sizeof(state->name_buffer_), "oem_%u", uid); @@ -440,7 +448,11 @@ 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 (!is_oem_id(gid)) { - return NULL; + return nullptr; + } + + if (vendor_group.FindById(gid, state)) { + return &state->group_; } snprintf(state->group_name_buffer_, sizeof(state->group_name_buffer_), @@ -530,6 +542,13 @@ passwd* getpwnam(const char* login) { // NOLINT: implementing bad function. if (pw != NULL) { return pw; } + + if (vendor_passwd.FindByName(login, state)) { + if (is_oem_id(state->passwd_.pw_uid)) { + return &state->passwd_; + } + } + // Handle OEM range. pw = oem_id_to_passwd(oem_id_from_name(login), state); if (pw != NULL) { @@ -640,6 +659,13 @@ static group* getgrnam_internal(const char* name, group_state_t* state) { if (grp != NULL) { return grp; } + + if (vendor_group.FindByName(name, state)) { + if (is_oem_id(state->group_.gr_gid)) { + return &state->group_; + } + } + // Handle OEM range. grp = oem_id_to_group(oem_id_from_name(name), state); if (grp != NULL) { |