mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-04-24 23:10:49 +02:00
dns-manager: don't replace /etc/resolv.conf installed by other tools
Resolves: * https://bugzilla.gnome.org/show_bug.cgi?id=732941 * https://bugzilla.redhat.com/show_bug.cgi?id=1116999 Acked-By: Dan Williams <dcbw@redhat.com> Acked-By: Thomas Haller <thaller@redhat.com>
This commit is contained in:
parent
4805be2ed2
commit
583568e12f
1 changed files with 35 additions and 0 deletions
|
|
@ -27,6 +27,7 @@
|
|||
#include <fcntl.h>
|
||||
#include <resolv.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
|
@ -446,6 +447,7 @@ update_resolv_conf (char **searches,
|
|||
GError **error)
|
||||
{
|
||||
FILE *f;
|
||||
struct stat st;
|
||||
|
||||
g_return_val_if_fail (error != NULL, FALSE);
|
||||
|
||||
|
|
@ -488,6 +490,39 @@ update_resolv_conf (char **searches,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
/* Don't overwrite a symbolic link unless it points to MY_RESOLV_CONF. */
|
||||
if (lstat (_PATH_RESCONF, &st) != -1) {
|
||||
/* Don't overwrite a symbolic link. */
|
||||
if (S_ISLNK (st.st_mode)) {
|
||||
if (stat (_PATH_RESCONF, &st) != -1) {
|
||||
char *path = g_file_read_link (_PATH_RESCONF, NULL);
|
||||
gboolean not_ours = g_strcmp0 (path, MY_RESOLV_CONF) != 0;
|
||||
|
||||
g_free (path);
|
||||
if (not_ours)
|
||||
return TRUE;
|
||||
} else {
|
||||
if (errno != ENOENT)
|
||||
return TRUE;
|
||||
g_set_error (error,
|
||||
NM_MANAGER_ERROR,
|
||||
NM_MANAGER_ERROR_FAILED,
|
||||
"Could not stat %s: %s\n",
|
||||
_PATH_RESCONF,
|
||||
g_strerror (errno));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
} else if (errno != ENOENT) {
|
||||
g_set_error (error,
|
||||
NM_MANAGER_ERROR,
|
||||
NM_MANAGER_ERROR_FAILED,
|
||||
"Could not lstat %s: %s\n",
|
||||
_PATH_RESCONF,
|
||||
g_strerror (errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (unlink (RESOLV_CONF_TMP) == -1 && errno != ENOENT) {
|
||||
g_set_error (error,
|
||||
NM_MANAGER_ERROR,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue