Merge "init: switch from android_ids to getpwnam"

am: 171504f

* commit '171504f8318b8d48c830bef3b9ff1451d76037b2':
  init: switch from android_ids to getpwnam

Change-Id: Idf79bfd2cf6436819447f12bce934329692012cd
This commit is contained in:
William Roberts 2016-04-08 01:51:37 +00:00 committed by android-build-merger
commit 43cbd0585b

View file

@ -23,6 +23,7 @@
#include <errno.h> #include <errno.h>
#include <time.h> #include <time.h>
#include <ftw.h> #include <ftw.h>
#include <pwd.h>
#include <selinux/label.h> #include <selinux/label.h>
#include <selinux/android.h> #include <selinux/android.h>
@ -39,38 +40,24 @@
#include <cutils/sockets.h> #include <cutils/sockets.h>
#include <android-base/stringprintf.h> #include <android-base/stringprintf.h>
#include <private/android_filesystem_config.h>
#include "init.h" #include "init.h"
#include "log.h" #include "log.h"
#include "property_service.h" #include "property_service.h"
#include "util.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) static unsigned int do_decode_uid(const char *s)
{ {
unsigned int v; unsigned int v;
if (!s || *s == '\0') if (!s || *s == '\0')
return UINT_MAX; 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; errno = 0;
v = (unsigned int) strtoul(s, 0, 0); v = (unsigned int) strtoul(s, 0, 0);