Use getpwnam() instead of AID_* macros

AID_* values are defined in libcutils private headers and hence
is not exported. Use getpwnam() instead to get these values.

Test: pass
Bug: 63135587
Change-Id: I748019e5351be9b386a2dec2e3ca7b613cc6732d
Merged-In: I748019e5351be9b386a2dec2e3ca7b613cc6732d
diff --git a/src/utils/os_unix.c b/src/utils/os_unix.c
index 26fd172..b516cc4 100644
--- a/src/utils/os_unix.c
+++ b/src/utils/os_unix.c
@@ -12,9 +12,11 @@
 #include <sys/wait.h>
 
 #ifdef ANDROID
+#include <grp.h>
+#include <pwd.h>
 #include <sys/capability.h>
 #include <sys/prctl.h>
-#include <private/android_filesystem_config.h>
+#include <sys/types.h>
 #endif /* ANDROID */
 
 #ifdef __MACH__
@@ -324,24 +326,42 @@
 int os_program_init(void)
 {
 #ifdef ANDROID
+	struct __user_cap_header_struct header;
+	struct __user_cap_data_struct cap;
+	struct group *grp = getgrnam("wifi");
+	gid_t gid_wifi = grp ? grp->gr_gid : 0;
+	struct passwd *pwd = getpwnam("wifi");
+	uid_t uid_wifi = pwd ? pwd->pw_uid : 0;
+
 	/*
 	 * We ignore errors here since errors are normal if we
 	 * are already running as non-root.
 	 */
 #ifdef ANDROID_SETGROUPS_OVERRIDE
 	gid_t groups[] = { ANDROID_SETGROUPS_OVERRIDE };
+
+	if (!gid_wifi || !uid_wifi) return -1;
 #else /* ANDROID_SETGROUPS_OVERRIDE */
-	gid_t groups[] = { AID_INET, AID_WIFI, AID_KEYSTORE };
+	gid_t groups[3];
+
+	if (!gid_wifi || !uid_wifi) return -1;
+	groups[0] = gid_wifi;
+
+	grp = getgrnam("inet");
+	groups[1] = grp ? grp->gr_gid : 0;
+	if (!groups[1]) return -1;
+
+	grp = getgrnam("keystore");
+	groups[2] = grp ? grp->gr_gid : 0;
+	if (!groups[2]) return -1;
 #endif /* ANDROID_SETGROUPS_OVERRIDE */
-	struct __user_cap_header_struct header;
-	struct __user_cap_data_struct cap;
 
 	setgroups(ARRAY_SIZE(groups), groups);
 
 	prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
 
-	setgid(AID_WIFI);
-	setuid(AID_WIFI);
+	setgid(gid_wifi);
+	setuid(uid_wifi);
 
 	header.version = _LINUX_CAPABILITY_VERSION;
 	header.pid = 0;