summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Holdsworth <joel.holdsworth@vcatechnology.com>2016-01-26 22:48:41 +0000
committerThomas Haller <thaller@redhat.com>2016-01-29 17:33:48 +0100
commit55a07b4ca4164608870d0f354943055bf16c8470 (patch)
treecfe128c3ccbb1f39f53f623a3aa128671cc671c3
parent17c5e4ec654bcea00ac729886ca2ed31cc4cee5b (diff)
settings: resolve path if hostname is a sym-link
If the hostname file is a symbolic link, follow it to find where the real file is located, otherwise g_file_set_contents will attempt to replace the link with a plain file. https://mail.gnome.org/archives/networkmanager-list/2016-January/msg00061.html https://mail.gnome.org/archives/networkmanager-list/2016-January/msg00073.html
-rw-r--r--src/settings/nm-settings.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index f6f8c3743e..688da2f8fa 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -1532,11 +1532,11 @@ write_hostname (NMSettingsPrivate *priv, const char *hostname)
char *hostname_eol;
gboolean ret;
gs_free_error GError *error = NULL;
- const char *file = priv->hostname.file;
+ char *file = priv->hostname.file, *link_path = NULL;
gs_unref_variant GVariant *var = NULL;
+ struct stat file_stat = { .st_mode = 0 };
#if HAVE_SELINUX
security_context_t se_ctx_prev = NULL, se_ctx = NULL;
- struct stat file_stat = { .st_mode = 0 };
mode_t st_mode = 0;
#endif
@@ -1554,6 +1554,14 @@ write_hostname (NMSettingsPrivate *priv, const char *hostname)
return !error;
}
+ /* If the hostname file is a symbolic link, follow it to find where the
+ * real file is located, otherwise g_file_set_contents will attempt to
+ * replace the link with a plain file.
+ */
+ if (lstat (file, &file_stat) == 0 && S_ISLNK (file_stat.st_mode) &&
+ (link_path = g_file_read_link (file, NULL)))
+ file = link_path;
+
#if HAVE_SELINUX
/* Get default context for hostname file and set it for fscreate */
if (stat (file, &file_stat) == 0)
@@ -1584,6 +1592,7 @@ write_hostname (NMSettingsPrivate *priv, const char *hostname)
#endif
g_free (hostname_eol);
+ g_free (link_path);
if (!ret) {
nm_log_warn (LOGD_SETTINGS, "Could not save hostname to %s: %s", file, error->message);