Require vendor users and groups to start with vendor_
Require that users and groups found in /vendor/etc/{passwd,group}
start with vendor_. This is needed to compliance with Treble as
without this prefix, it is possible for a new system image to create a
user/group name that a vendor has already used, causing a collision.
Bug: 79528966
Test: new unit test
Change-Id: I07500641e165f41526a8101592d83fa174e7a711
diff --git a/libc/bionic/grp_pwd_file.h b/libc/bionic/grp_pwd_file.h
index 048cd82..29d75f4 100644
--- a/libc/bionic/grp_pwd_file.h
+++ b/libc/bionic/grp_pwd_file.h
@@ -37,7 +37,7 @@
class MmapFile {
public:
- MmapFile(const char* filename);
+ MmapFile(const char* filename, const char* required_prefix);
template <typename Line>
bool FindById(uid_t uid, Line* line);
@@ -65,11 +65,12 @@
const char* filename_ = nullptr;
const char* start_ = nullptr;
const char* end_ = nullptr;
+ const char* required_prefix_;
};
class PasswdFile {
public:
- PasswdFile(const char* filename);
+ PasswdFile(const char* filename, const char* required_prefix);
bool FindById(uid_t id, passwd_state_t* passwd_state);
bool FindByName(const char* name, passwd_state_t* passwd_state);
@@ -85,7 +86,7 @@
class GroupFile {
public:
- GroupFile(const char* filename);
+ GroupFile(const char* filename, const char* required_prefix);
bool FindById(gid_t id, group_state_t* group_state);
bool FindByName(const char* name, group_state_t* group_state);