Commit graph

34 commits

Author SHA1 Message Date
Elliott Hughes
7cebf835f3 Various coverage improvements.
Mostly from extra test cases, but also:

* Move the fgets size < 0 assertion into fgets.

* Use ELF aliases for strtoq/strtouq rather than duplicating code.

* Don't check uname() succeeded, since it can't fail.

Test: treehugger
Change-Id: I2e6b3b88b0a3eb16bd68be68b9bc9f40d8043291
2020-08-12 15:52:14 -07:00
Tom Cherry
b9fa04d805 Don't test pw_shell for old vendor images
R GSI on P product tests fail since pw_shell has changed.  This value
has no practical use on Android, so we ignore testing it for older
vendor images.

Bug: 160937247
Test: this test does/doesn't run appropriately
Change-Id: Ie485bd019b3826e71ad19131effcbb002f888d52
2020-07-10 10:42:16 -07:00
Tom Cherry
0816c9050f Tighten pwd/grp iteration tests.
Previously, these tests would fail if vendors modified
private/android_filesystem_config.h to add their custom AIDs, but we
did not have a good alternative that vendors could use, so we added a
special case to ignore the vendor AID ranges.

We've had a proper solution since P for this range, so it's long past
time to remove this special case.

Test: add system, vendor, odm, product, and system_ext AIDs to
      config.fs, ensure that they've taken effect on cuttlefish,
      pass these unit tests
Change-Id: I6c9c2bf5e895c25805222da018188b269777171c
2020-04-10 13:00:42 -07:00
Tom Cherry
6f2e810198 Cleanup some trivial TODOs.
1) "fix the system properties design" is written for the old protocol,
   so we've already changed the design.  There are no other further
   planned changes.
2) "don't drag in all the macros, just the types." is not likely to
   happen or be particularly impactful.
3) "Find a location suitable for these functions ..." is refering to
   legacy code.  More likely that this code will be removed before we
   find a serious reason to fix this TODO.
4) "(73062966) We still don't have a good way ..." is stale; we fixed
   this bug and added the appropriate mechanism.

Test: n/a
Change-Id: I23991692cdeb81ad00844a6a1680900ff384208b
2020-04-10 11:46:03 -07:00
Elliott Hughes
95c6cd753f Stop using the __ANDROID_API_x__ constants.
Historically we've made a few mistakes where they haven't matched the
right number. And most non-Googlers are much more familiar with the
numbers, so it seems to make sense to rely more on them. Especially in
header files, which we actually expect real people to have to read from
time to time.

Test: treehugger
Change-Id: I0d4a97454ee108de1d32f21df285315c5488d886
2019-12-20 13:26:14 -08:00
Tom Cherry
777b34dcc3 Load /etc/{passwd,group} from all partitions
Note that unlike the oem_ range that is used for the vendor
partitions, we do not create oem_<n> entries for these new reserved
ranges; they will only appear in getpwent()/getgrent() if there is an
entry in the corresponding passwd/group file.

Bug: 73062966
Test: can load AIDs from partitions other than vendor
Test: bionic-unit-tests
Change-Id: Ifcbbf202894adff948eaaba2a59e25c993611140
2019-07-11 10:31:02 -07:00
Tom Cherry
6b116d1bbf Make 'app' users/groups more accurate
In an attempt to make bionic's reporting of users and groups more
accurate, this change makes the user / group functions do the
following:

1) Fail to query a uid/gid for a secondary user when the uid/gid
   doesn't exist.  Currently bionic would return successfully but with
   a empty string for the name.
2) Fail to query a platform uid/gid, except a limited pre-allocated
   set for a secondary user, as these are not used by second users.
3) Fail to query uids for all users for the GID-only app ranges:
   CACHE_GID, EXT_GID, EXT_CACHE_GID, SHARED_GID.
4) Fail to query gids in SHARED_GID range for secondary users, as
   these GIDs are only allocated for the first user.
5) Use "u#_a#_ext" and u#_a#_ext_cache" for EXT_GID and EXT_CACHE_GID
   ranges.  This both allows querying based on these names and
   returning these names for the appropriate uids/gids.

This also consolidates the tests for better readability.

Test: these unit tests, boot

Change-Id: I59a1af0792e7806d423439582e56ce7f9f801c94
2019-05-29 15:54:50 -07:00
Tom Cherry
c57c5bdb7f pwd/grp: fix pwd _r reentrancy, new tests, clean up
getpwnam_r() and getpwuid_r() clobber the storage used by getpwnam()
and getpwuid().  This isn't likely to be a big issue, but since we do
this right for the group functions, fix this as well as add a test.
Both use more space in buf than is actually required, but well below
their sysconf() suggested values, so we accept that to keep the code
concise.

Add tests for dealing with unaligned input buffers, particularly for
getgrnam_r() and getgrgid_r(), as they require alignment but this
wasn't being tested.

Refactor common initialization code for both passwd and group state
structs.

Remove extraneous null pointer checks; the values they were testing
were offsets of a previous pointer, so guaranteed to never actually be
null.  If the underlying pointer is actually null, we're beyond repair
anyway, so accept that we'll crash.

Test: pwd/grp unit tests

Change-Id: I60c4d00e9ab3cf55daf8314c5029fd914025b696
2019-05-15 15:49:34 -07:00
Elliott Hughes
bcaa454d32 bionic tests: use GTEST_SKIP.
Also be a bit more to the point in our messages, focusing on "why" not
"what".

Test: ran tests
Change-Id: I297806c7a102bd52602dcd2fcf7a2cd34aba3a11
2019-03-12 10:26:39 -07:00
Tom Cherry
9da8ff1270 Waive AID Range check for devices through Q
We still don't have a good way to create vendor AIDs in the system or
other non-vendor partitions, therefore we keep this check disabled.

Bug: 73062966
Test: treehugger
Change-Id: I7aed425899d6ec11a22702ccec82476eacdbc790
2019-02-19 13:24:59 -08:00
Martijn Coenen
f9d2299ee2 Update getpwnam() tests to correctly handle new app zygote uids.
The UID range [90000..98999] is used for isolated processes that are
spawned from an application zygote. Otherwise they are identical to
regular isolated processes in the [99000..99999] range. Fix the tests to
match the new range.

Bug: 111434506
Test: atest bionic-unit-tests-static
Change-Id: Id0352f2cf0d21edb04d95f01ea2548e95b62317a
2019-01-17 13:36:47 +01:00
Chuwei Xu
5d9312bb13 CTS: allow continue to use the old AIDs on devices launch with P
Some vendors may have been using the AIDs outside the oem ranges
for long that those aids need continue to be maitained for the
existing devices. We allow them countinue to use the old AID names
and values on device launch with P and before, to give them the
period of time to adopt the new AID scheme.

Bug: 116405200
Change-Id: I0453ed14df4c0855575ef1404c596ddc6ded681b
2018-10-23 13:50:04 +08:00
Tom Cherry
5c941435ac Waive AID Range check for upgrading devices launched before P
We added a check in P that ensures all vendor provided AIDs only
appear in the carved out ranges for vendors to use.  However,
upgrading devices may be using AIDs outside of this range and it is
very difficult to change these AIDs, so we waive this test for them.

Bug: 116830906
Test: test succeeds on upgrading devices
Change-Id: Iddcacb1dce77a150d5138e7b3115abf25bf60a6e
2018-10-11 11:57:13 -07:00
Tom Cherry
fa5f61c8d9 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
2018-09-27 20:29:49 +00:00
Yi Kong
32bc0fcf69 Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.

Test: m
Bug: 68236239
Change-Id: I5b4123bc6709641315120a191e36cc57541349b2
2018-08-02 18:09:44 -07:00
Tom Cherry
4cddb00d6f Reland "Remove a check for AIDs in the OEM range."
There may be vendor extensions to the system image which would need to
use these IDs.

This reverts commit 41986a013a.

Bug: 110856218
Test: these tests
2018-06-29 10:39:43 -07:00
Tom Cherry
e88b4083e4 Test that vendor AID names begin with vendor_
Now that we're only processing vendor AID names that begin with
vendor_, add an explicit test to fail devices that use AID names
without this prefix.

Bug: 79528966
Test: Pass if no vendor defined AIDs are present
Test: Pass if vendor defined AIDs are present with vendor_ prefix
Test: Fail if vendor defined AIDs are present without vendor_ prefix

Change-Id: I77c559800b4904f58c49fbe339e4daad7d953089
2018-05-24 14:44:10 -07:00
Tom Cherry
b4c25c882e Do not check user/group names in pwd/grp tests for OEM uid/gids
Vendors that use config.fs will have their own uniquely named
user/group names for uids/gids that fall in the OEM ranges.  We
continue to allow lookup via oem_## for these values, however the
returned structs will always include the name from config.fs, so we do
not check it for anything in the tests.

Bug: 77549259
Test: bionic unit tests with uid 5000 as AID_CRAS
Change-Id: I27fc1fdd0e22063fea82b4c9d2a6fb8b865c5d7b
2018-04-04 15:02:55 -07:00
Josh Gao
2fe1034a02 Disable {getpwent,getgrent}_iterate tests on glibc.
These tests aren't meaningful on the host, and take forever to fail.

Test: bionic-unit-tests-glibc --gtest_filter="*get??ent_iterate"
Change-Id: I8ca20829ba94f2ea815c636f779bacc55449cffd
2018-02-27 14:25:56 -08:00
Tom Cherry
41986a013a Revert "Remove a check for AIDs in the OEM range."
We now have a proper mechanism for OEMs to create new AIDs via
config.fs and /vendor/etc/{passwd,group}.  This means that there is no
reason for OEMs to add AIDs by modifying android_filesystem_config.h,
and therefore we can add this check back.

Bug: 27999086
Test: pwd and grp tests pass with custom AIDs in config.fs

This reverts commit a14485adde.

Change-Id: I74a28ff267a595e83cf692b27fd8b5170a021f54
2018-02-12 10:49:13 -08:00
Tom Cherry
4362f897f7 Only use uids and gids for which we've allocated AIDs
Currently, getpwnam, getpwent, etc return successfully for any uid
from AID_APP_START (10000) to AID_USER_OFFSET (100000) for each user.
This is not correct however, as only specific ranges above
AID_APP_START are reserved as valid ranges.  This change corrects this.

This is particularly important as the newly added AID_OVERFLOWUID is
65534, which is above AID_APP_START but not in any reserved range,
collided with the faulty returned values.

Bug: 69119022
Bug: 69128408
Test: pwd/grp bionic unit tests
Change-Id: I3dae97a90597915fa30a88fe27cda88b107e9c35
2017-11-15 10:31:49 -08:00
Tom Cherry
2c05c0f9b0 Better test handling and logging in grp_pwd_test.cpp
grp_pwd_test.cpp uses ASSERT_ where EXPECT_ is possible, causing
missing failures when multiple failures are present.

Also, print out the uid/gid in the _iterate tests, to make debugging
easier.

Test: these same unit tests
Change-Id: I839b74fb86232b3e896091e76ab862cc5b6b8782
2017-11-10 10:57:21 -08:00
Tom Cherry
a14485adde Remove a check for AIDs in the OEM range.
Remove the check that AIDs in the OEM range are not defind in
android_filesystem_config, as we do not yet have a good solution for
OEMs to define custom AIDs and what OEMs are currently doing isn't
hurting anything.

Bug: b/64137613
Test: pwd.getpwent_iterate / grp.getgrent_iterate
Change-Id: If98ad4443fe9e827e3f17b3df92eca82763e6290
2017-08-04 18:15:58 +00:00
Elliott Hughes
45be5dfe98 Revert "Revert "move android_ids into bionic""
am: 3f6eee9793

Change-Id: I6a65710f926a76e48705fa4594f479f5d48df068
2017-01-10 01:23:26 +00:00
Jeff Sharkey
54891837a0 Merge "Define range of GIDs for cached app data." 2016-12-15 21:46:30 +00:00
Elliott Hughes
3f6eee9793 Revert "Revert "move android_ids into bionic""
This reverts commit 77cb68d9f2.

Change-Id: Ibc9f775c4cd418be90fd8a6f192dd72ca5dff09a
2016-12-13 23:47:25 +00:00
Elliott Hughes
9f9c73bb2e Merge "Rename <grp.h>/<pwd.h> tests to fit the usual pattern." 2016-12-13 22:53:25 +00:00
Jeff Sharkey
934bc86df3 Define range of GIDs for cached app data.
To support upcoming disk usage calculation optimizations, this change
creates a new GID for each app that will be used to mark its cached
data.  We're allocating these unique GIDs so that we can use
quotactl() to track cached data on a per-app basis.

Test: builds, boots, tests pass
Bug: 27948817
Change-Id: Ic00c39ccedc23d5d43988029e9921679126f8f2d
2016-12-13 14:22:55 -07:00
Elliott Hughes
5367d1b9d9 Rename <grp.h>/<pwd.h> tests to fit the usual pattern.
Bug: N/A
Test: ran tests
Change-Id: I5ec30cc17f94e631f3376b671055a0e82fb472c3
2016-12-12 17:32:14 -08:00
Elliott Hughes
77cb68d9f2 Revert "move android_ids into bionic"
This reverts commit 1a13db5b26.

Change-Id: I7f571b3a9d542694d16fb9cf1131ef9e59d330ea
2016-12-12 22:11:37 +00:00
William Roberts
1a13db5b26 move android_ids into bionic
Generate the android_ids array and include into the
build.

Test: The bionic is built and that core AIDs work as
expected with commands like chown, mkdir and init services
and builtins.
Bug: 27999086
Change-Id: Ib575bf85326c91801c5674db475dcb9cf44c00dc
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2016-11-30 12:54:08 -08:00
Mark Salyzyn
722ab05b25 bionic: Implement getpwent and getgrent
Not efficient to iterate through given the large number of Android
ids (AID). Compile warning will result if you use these functions,
telling you as much. Not for general consumption, however for
example, some filesystem tests would like to see these to perform
all corners.

About 1/4 second for getpwent, and 1/8 second for getgrent to iterate
through all reserved Android aids.

Bug: 27999086
Change-Id: I7784273b7875c38e4954ae21d314f35e4bf8c2fc
2016-04-22 10:44:19 -07:00
Mark Salyzyn
8d387ee1ec fix oem_XXXX ids to incorporate both ranges
The XXXX now lines up to the underlying uid and has no offset.
Work with AID_OEM_RESERVED uids.

Test uses hard coded values to catch changes in the API expectations
that may occur in private/android_filesystem_config.h.

SideEffects: names change, some product dependencies.

Bug: 27999086
Change-Id: Ic2b4c36de74ae009a44e14711c75834293828207
2016-04-06 21:18:49 +00:00
Elliott Hughes
3735539fc3 Rename the <grp.h>/<pwd.h> tests to reflect that they're no longer in stubs.cpp.
Bug: http://b/27999086
Change-Id: I3255ad5861a705beeb9b462e22f79ae1e5a85a79
2016-04-06 09:04:17 -07:00
Renamed from tests/stubs_test.cpp (Browse further)