[PATCH] Allow RW access to wpa_supplicant config file

Dmitry Shmidt dimitrysh
Fri Feb 25 14:22:11 PST 2011


Signed-off-by: Dmitry Shmidt <dimitrysh at google.com>
---
 wpa_supplicant/Makefile      |    4 ++++
 wpa_supplicant/config_file.c |   11 ++++++++++-
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/wpa_supplicant/Makefile b/wpa_supplicant/Makefile
index cbcf30a..b77c71e 100644
--- a/wpa_supplicant/Makefile
+++ b/wpa_supplicant/Makefile
@@ -1216,6 +1216,10 @@ ifndef CONFIG_MAIN
 CONFIG_MAIN=main
 endif

+ifdef CONFIG_RW_CONFIG_FILE
+CFLAGS += -DCONFIG_RW_CONFIG_FILE
+endif
+
 ifdef CONFIG_DEBUG_SYSLOG
 CFLAGS += -DCONFIG_DEBUG_SYSLOG
 endif
diff --git a/wpa_supplicant/config_file.c b/wpa_supplicant/config_file.c
index 09c99e3..87fcbbd 100644
--- a/wpa_supplicant/config_file.c
+++ b/wpa_supplicant/config_file.c
@@ -22,7 +22,9 @@
 #include "config.h"
 #include "base64.h"
 #include "uuid.h"
-
+#ifdef CONFIG_RW_CONFIG_FILE
+#include <sys/stat.h>
+#endif

 /**
  * wpa_config_get_line - Read the next configuration file line
@@ -288,6 +290,13 @@ struct wpa_config * wpa_config_read(const char *name)
 		return NULL;
 	}

+#ifdef CONFIG_RW_CONFIG_FILE
+	/* When creating the config file, give group read/write access
+	 * to allow backup and restoring the file.
+	 */
+	chmod(name, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
+#endif
+
 	while (wpa_config_get_line(buf, sizeof(buf), f, &line, &pos)) {
 		if (os_strcmp(pos, "network={") == 0) {
 			ssid = wpa_config_read_network(f, &line, id++);
-- 
1.7.3.1



More information about the Hostap mailing list