From 3792e6cf21f0c9fbf64898ec68350e942923f33d Mon Sep 17 00:00:00 2001 From: William Roberts Date: Wed, 6 Apr 2016 19:18:50 -0700 Subject: [PATCH] init: switch from android_ids to getpwnam Start to move users of android_filesystem_config.h to use the standard grp and pwd interface functions. Advantages: * one copy of android_ids in libc, removing it from init objects. * immediately starts oem_xxx users and groups in rc. * future will support _named_ oem ids via backend improvements. Change-Id: Ib1ae1e0cbdcaaf60deb3759681a6030b615c069c Bug: 27999086 Signed-off-by: William Roberts --- init/util.cpp | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/init/util.cpp b/init/util.cpp index 4d36dfd0a..750e04090 100644 --- a/init/util.cpp +++ b/init/util.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -39,38 +40,24 @@ #include #include -#include - #include "init.h" #include "log.h" #include "property_service.h" #include "util.h" -/* - * android_name_to_id - returns the integer uid/gid associated with the given - * name, or UINT_MAX on error. - */ -static unsigned int android_name_to_id(const char *name) -{ - const struct android_id_info *info = android_ids; - unsigned int n; - - for (n = 0; n < android_id_count; n++) { - if (!strcmp(info[n].name, name)) - return info[n].aid; - } - - return UINT_MAX; -} - static unsigned int do_decode_uid(const char *s) { unsigned int v; if (!s || *s == '\0') return UINT_MAX; - if (isalpha(s[0])) - return android_name_to_id(s); + + if (isalpha(s[0])) { + struct passwd* pwd = getpwnam(s); + if (!pwd) + return UINT_MAX; + return pwd->pw_uid; + } errno = 0; v = (unsigned int) strtoul(s, 0, 0);