Android-x86
Fork
Faire un don

  • R/O
  • HTTP
  • SSH
  • HTTPS

external-wpa_supplicant_8: Commit

external/wpa_supplicant_8


Commit MetaInfo

Révision0a217de1802bc5cf785524c1913af7ae3faa9c54 (tree)
l'heure2015-02-06 08:46:52
AuteurVinit Deshpande <vinitd@goog...>
CommiterVinit Deshpande

Message de Log

Don't write to wpa_supplicant.conf directly

There is a chance that wpa_supplicant may get killed during
the time it is writing config file. If this happens, user
information like SSIDs and passwords can be lost forever.

This change works around that by writing config to a
temporary file and then renaming the file to the correct name.

Bug: 19224089

Change-Id: I1709cdd5e5c6dfa3073e42c644fae941b43401cc
Signed-off-by: Vinit Deshpande <vinitd@google.com>

Change Summary

Modification

--- a/wpa_supplicant/config_file.c
+++ b/wpa_supplicant/config_file.c
@@ -20,6 +20,9 @@
2020 #include "eap_peer/eap_methods.h"
2121 #include "eap_peer/eap.h"
2222
23+#ifdef ANDROID
24+#include <sys/stat.h>
25+#endif
2326
2427 static int newline_terminated(const char *buf, size_t buflen)
2528 {
@@ -1205,12 +1208,21 @@ int wpa_config_write(const char *name, struct wpa_config *config)
12051208 struct wpa_config_blob *blob;
12061209 #endif /* CONFIG_NO_CONFIG_BLOBS */
12071210 int ret = 0;
1211+ int tmp_len = os_strlen(name) + 5; /* allow space for .tmp suffix */
1212+ char *tmp_name = os_malloc(tmp_len);
12081213
1209- wpa_printf(MSG_DEBUG, "Writing configuration file '%s'", name);
1214+ if (tmp_name == NULL)
1215+ tmp_name = (char *)name;
1216+ else
1217+ os_snprintf(tmp_name, tmp_len, "%s.tmp", name);
1218+
1219+ wpa_printf(MSG_DEBUG, "Writing configuration file '%s'", tmp_name);
12101220
1211- f = fopen(name, "w");
1221+ f = fopen(tmp_name, "w");
12121222 if (f == NULL) {
1213- wpa_printf(MSG_DEBUG, "Failed to open '%s' for writing", name);
1223+ wpa_printf(MSG_DEBUG, "Failed to open '%s' for writing", tmp_name);
1224+ if (tmp_name != name)
1225+ os_free(tmp_name);
12141226 return -1;
12151227 }
12161228
@@ -1245,6 +1257,17 @@ int wpa_config_write(const char *name, struct wpa_config *config)
12451257
12461258 fclose(f);
12471259
1260+ if (tmp_name != name) {
1261+ int chmod_ret = 0;
1262+#ifdef ANDROID
1263+ chmod_ret = chmod(tmp_name, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
1264+#endif
1265+ if (chmod_ret != 0 || rename(tmp_name, name) != 0)
1266+ ret = -1;
1267+
1268+ os_free(tmp_name);
1269+ }
1270+
12481271 wpa_printf(MSG_DEBUG, "Configuration file '%s' written %ssuccessfully",
12491272 name, ret ? "un" : "");
12501273 return ret;
Afficher sur ancien navigateur de dépôt.