Accumulative patch from commit ce26864e79144cba12d5ff98632570593cc57b8a

187f87f hostapd: Allow ctrl_iface group to be specified on command line
9f890c9 TDLS: Support both external and internal setup in disabling link
864fe3a TDLS: Fix TDLS Setup Request processing in existing-peer cases
1d43e28 TDLS: Fix TPK M2 processing in concurrent initiation case
ef8151a P2P: Write p2p_ignore_shared_freq to configuration file on updates
8047f70 P2P: Ignore Tx acknowledgment status for Invitation Response
18a2eaa Add ap_vendor_elements for wpa_supplicant AP/P2P GO mode
b084df8 Add vendor_elements into Beacon/Probe Response IE parameters
b92e08f nl80211: Add debug prints for set_ap parameters
c30a4ab nl80211: Fix mode settings with split wiphy dump

Change-Id: I859638e630b6ca32b64e09943fce4d96f779897b
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
diff --git a/hostapd/main.c b/hostapd/main.c
index d4256d0..4b0da3c 100644
--- a/hostapd/main.c
+++ b/hostapd/main.c
@@ -9,6 +9,7 @@
 #include "utils/includes.h"
 #ifndef CONFIG_NATIVE_WINDOWS
 #include <syslog.h>
+#include <grp.h>
 #endif /* CONFIG_NATIVE_WINDOWS */
 
 #include "utils/common.h"
@@ -480,7 +481,8 @@
 		"\n"
 		"usage: hostapd [-hdBKtv] [-P <PID file>] [-e <entropy file>] "
 		"\\\n"
-		"         [-g <global ctrl_iface>] <configuration file(s)>\n"
+		"         [-g <global ctrl_iface>] [-G <group>] \\\n"
+		"         <configuration file(s)>\n"
 		"\n"
 		"options:\n"
 		"   -h   show this usage\n"
@@ -488,6 +490,7 @@
 		"   -B   run daemon in the background\n"
 		"   -e   entropy file\n"
 		"   -g   global control interface path\n"
+		"   -G   group for control interfaces\n"
 		"   -P   PID file\n"
 		"   -K   include key data in debug messages\n"
 #ifdef CONFIG_DEBUG_FILE
@@ -531,6 +534,22 @@
 }
 
 
+static int hostapd_get_ctrl_iface_group(struct hapd_interfaces *interfaces,
+					const char *group)
+{
+#ifndef CONFIG_NATIVE_WINDOWS
+	struct group *grp;
+	grp = getgrnam(group);
+	if (grp == NULL) {
+		wpa_printf(MSG_ERROR, "Unknown group '%s'", group);
+		return -1;
+	}
+	interfaces->ctrl_iface_group = grp->gr_gid;
+#endif /* CONFIG_NATIVE_WINDOWS */
+	return 0;
+}
+
+
 int main(int argc, char *argv[])
 {
 	struct hapd_interfaces interfaces;
@@ -556,7 +575,7 @@
 	interfaces.global_ctrl_sock = -1;
 
 	for (;;) {
-		c = getopt(argc, argv, "Bde:f:hKP:tvg:");
+		c = getopt(argc, argv, "Bde:f:hKP:tvg:G:");
 		if (c < 0)
 			break;
 		switch (c) {
@@ -594,7 +613,9 @@
 		case 'g':
 			hostapd_get_global_ctrl_iface(&interfaces, optarg);
 			break;
-
+		case 'G':
+			hostapd_get_ctrl_iface_group(&interfaces, optarg);
+			break;
 		default:
 			usage();
 			break;