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/common/wpa_ctrl.c b/src/common/wpa_ctrl.c
index 623c2a7..a0fe822 100644
--- a/src/common/wpa_ctrl.c
+++ b/src/common/wpa_ctrl.c
@@ -21,9 +21,11 @@
 
 #ifdef ANDROID
 #include <dirent.h>
+#include <grp.h>
+#include <pwd.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 #include <cutils/sockets.h>
-#include "private/android_filesystem_config.h"
 #endif /* ANDROID */
 
 #ifdef CONFIG_CTRL_IFACE_UDP_IPV6
@@ -98,6 +100,12 @@
 	size_t res;
 	int tries = 0;
 	int flags;
+#ifdef ANDROID
+	struct group *grp_wifi;
+	gid_t gid_wifi;
+	struct passwd *pwd_system;
+	uid_t uid_system;
+#endif
 
 	if (ctrl_path == NULL)
 		return NULL;
@@ -153,8 +161,18 @@
 #ifdef ANDROID
 	chmod(ctrl->local.sun_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
 	/* Set group even if we do not have privileges to change owner */
-	chown(ctrl->local.sun_path, -1, AID_WIFI);
-	chown(ctrl->local.sun_path, AID_SYSTEM, AID_WIFI);
+	grp_wifi = getgrnam("wifi");
+	gid_wifi = grp_wifi ? grp_wifi->gr_gid : 0;
+	pwd_system = getpwnam("system");
+	uid_system = pwd_system ? pwd_system->pw_uid : 0;
+	if (!gid_wifi || !uid_system) {
+		close(ctrl->s);
+		unlink(ctrl->local.sun_path);
+		os_free(ctrl);
+		return NULL;
+	}
+	chown(ctrl->local.sun_path, -1, gid_wifi);
+	chown(ctrl->local.sun_path, uid_system, gid_wifi);
 
 	if (os_strncmp(ctrl_path, "@android:", 9) == 0) {
 		if (socket_local_client_connect(