ifnet: backup configuration files before writing (bgo #670508)
This commit is contained in:
@@ -576,6 +576,8 @@ ifnet_flush_to_file (const char *config_file)
|
|||||||
if (!conn_table || !global_settings_table)
|
if (!conn_table || !global_settings_table)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
backup_file (config_file);
|
||||||
|
|
||||||
channel = g_io_channel_new_file (config_file, "w", NULL);
|
channel = g_io_channel_new_file (config_file, "w", NULL);
|
||||||
if (!channel) {
|
if (!channel) {
|
||||||
PLUGIN_WARN (IFNET_PLUGIN_NAME,
|
PLUGIN_WARN (IFNET_PLUGIN_NAME,
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <nm-utils.h>
|
#include <nm-utils.h>
|
||||||
#include <nm-system-config-interface.h>
|
#include <nm-system-config-interface.h>
|
||||||
|
#include <gio/gio.h>
|
||||||
#include "net_utils.h"
|
#include "net_utils.h"
|
||||||
#include "wpa_parser.h"
|
#include "wpa_parser.h"
|
||||||
#include "net_parser.h"
|
#include "net_parser.h"
|
||||||
@@ -949,3 +950,20 @@ get_dhcp_hostname_and_client_id (char **hostname, char **client_id)
|
|||||||
g_strfreev (all_lines);
|
g_strfreev (all_lines);
|
||||||
g_free (contents);
|
g_free (contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void backup_file (gchar* target)
|
||||||
|
{
|
||||||
|
GFile *source, *backup;
|
||||||
|
gchar* backup_path;
|
||||||
|
GError **error;
|
||||||
|
|
||||||
|
source = g_file_new_for_path (target);
|
||||||
|
backup_path = g_strdup_printf ("%s.bak", target);
|
||||||
|
backup = g_file_new_for_path (backup_path);
|
||||||
|
|
||||||
|
g_file_copy (source, backup, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, error);
|
||||||
|
if (error && *error)
|
||||||
|
PLUGIN_WARN (IFNET_PLUGIN_NAME, "Backup failed: %s", (*error)->message);
|
||||||
|
|
||||||
|
g_free (backup_path);
|
||||||
|
}
|
||||||
|
@@ -77,4 +77,5 @@ gboolean is_true (const char *str);
|
|||||||
|
|
||||||
void get_dhcp_hostname_and_client_id (char **hostname, char **client_id);
|
void get_dhcp_hostname_and_client_id (char **hostname, char **client_id);
|
||||||
|
|
||||||
|
void backup_file (gchar* target);
|
||||||
#endif
|
#endif
|
||||||
|
@@ -124,7 +124,7 @@ add_key_value (GHashTable * network, gchar * line)
|
|||||||
g_strstrip (key_value[0]);
|
g_strstrip (key_value[0]);
|
||||||
g_strstrip (key_value[1]);
|
g_strstrip (key_value[1]);
|
||||||
|
|
||||||
/* Reserve quotes for psk, wep_key, ssid
|
/* Reserve quotes for psk, wep_key, ssid
|
||||||
* Quotes will determine whether they are hex format */
|
* Quotes will determine whether they are hex format */
|
||||||
if (strcmp (key_value[0], "psk") != 0
|
if (strcmp (key_value[0], "psk") != 0
|
||||||
&& !g_str_has_prefix (key_value[0], "wep_key")
|
&& !g_str_has_prefix (key_value[0], "wep_key")
|
||||||
@@ -162,7 +162,7 @@ add_one_wep_key (GHashTable * table, int key_num, gchar * one_wep_key)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reading wep security information from /etc/conf.d/net.
|
/* Reading wep security information from /etc/conf.d/net.
|
||||||
* This should not be used in futre, use wpa_supplicant instead. */
|
* This should not be used in futre, use wpa_supplicant instead. */
|
||||||
static void
|
static void
|
||||||
add_keys_from_net ()
|
add_keys_from_net ()
|
||||||
@@ -376,6 +376,8 @@ wpa_flush_to_file (const char *config_file)
|
|||||||
if (!wsec_table || !wsec_global_table)
|
if (!wsec_table || !wsec_global_table)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
backup_file (config_file);
|
||||||
|
|
||||||
channel = g_io_channel_new_file (config_file, "w", NULL);
|
channel = g_io_channel_new_file (config_file, "w", NULL);
|
||||||
if (!channel) {
|
if (!channel) {
|
||||||
PLUGIN_WARN (IFNET_PLUGIN_NAME,
|
PLUGIN_WARN (IFNET_PLUGIN_NAME,
|
||||||
|
Reference in New Issue
Block a user