summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Roberts <william.c.roberts@intel.com>2016-04-10 17:47:07 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-04-10 17:47:07 +0000
commitbdc327bd33e9778e1e888f82f8b9bfebae1f5c30 (patch)
tree0b66273b0e5f24c22ba174ac78dabe24ffb63c81
parent02c42d4b17fb5b9fa1643e46ef1bfb31771c5194 (diff)
parent5f62b5073afe88699bfb2a7a036d1e0ef0d6a6b1 (diff)
downloadlibselinux-bdc327bd33e9778e1e888f82f8b9bfebae1f5c30.tar.gz
switch from android_ids to getpwuid
am: 5f62b50 * commit '5f62b5073afe88699bfb2a7a036d1e0ef0d6a6b1': switch from android_ids to getpwuid Change-Id: Id0ab82e24d459319730e46daadd537b046a51def
-rw-r--r--src/android.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/android.c b/src/android.c
index 7406ffa..b748ca5 100644
--- a/src/android.c
+++ b/src/android.c
@@ -563,6 +563,7 @@ static int seapp_context_lookup(enum seapp_kind kind,
const char *path,
context_t ctx)
{
+ struct passwd *pwd;
bool isOwner;
const char *username = NULL;
struct seapp_context *cur = NULL;
@@ -586,14 +587,19 @@ static int seapp_context_lookup(enum seapp_kind kind,
isOwner = (userid == 0);
appid = uid % AID_USER;
if (appid < AID_APP) {
- for (n = 0; n < android_id_count; n++) {
- if (android_ids[n].aid == appid) {
- username = android_ids[n].name;
- break;
- }
- }
- if (!username)
+ /*
+ * This code is Android specific, bionic guarantees that
+ * calls to non-reentrant getpwuid() are thread safe.
+ */
+#ifndef __BIONIC__
+#warning "This code assumes that getpwuid is thread safe, only true with Bionic!"
+#endif
+ pwd = getpwuid(appid);
+ if (!pwd)
goto err;
+
+ username = pwd->pw_name;
+
} else if (appid < AID_ISOLATED_START) {
username = "_app";
appid -= AID_APP;