mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 14:38:09 +02:00
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
This commit is contained in:
parent
17c5e4ec65
commit
55a07b4ca4
1 changed files with 11 additions and 2 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue