From 89ae703cd6d4b2bc86c4bd281a8e460fd5679891 Mon Sep 17 00:00:00 2001 From: Dmitry Shmidt Date: Mon, 7 Mar 2011 15:30:53 -0800 Subject: [PATCH] wifi: Ensure RW for wpa_supplicant.conf Change-Id: Icaeac0ee2239333be5f3be10024824ada6da18d5 Signed-off-by: Dmitry Shmidt --- wifi/wifi.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/wifi/wifi.c b/wifi/wifi.c index 0f62c04..132f723 100644 --- a/wifi/wifi.c +++ b/wifi/wifi.c @@ -229,8 +229,15 @@ int ensure_config_file_exists() int srcfd, destfd; struct stat sb; int nread; + int ret; - if (access(SUPP_CONFIG_FILE, R_OK|W_OK) == 0) { + ret = access(SUPP_CONFIG_FILE, R_OK|W_OK); + if ((ret == 0) || (errno == EACCES)) { + if ((ret != 0) && + (chmod(SUPP_CONFIG_FILE, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) != 0)) { + LOGE("Cannot set RW to \"%s\": %s", SUPP_CONFIG_FILE, strerror(errno)); + return -1; + } /* return if filesize is at least 10 bytes */ if (stat(SUPP_CONFIG_FILE, &sb) == 0 && sb.st_size > 10) { pbuf = malloc(sb.st_size + PROPERTY_VALUE_MAX);