Patch. Do not wipe out resolv.conf when there is no name servers returned by DHCP



When i connect through a PPTP to remote network and USEPEERDNS is
unselected, /etc/resolv.conf gets wiped out. This issue exists in Feisty
and in Gutsy too. I have made patch to correct this by simply not to
update resolv.conf (leave intact) when there is no name servers returned
by DHCP. Now PPTP is working for me correctly (as i expect).

--- src/named-manager/nm-named-manager.c.orig	2007-04-18 21:13:05.000000000 +0300
+++ src/named-manager/nm-named-manager.c	2007-10-25 11:52:23.000000000 +0300
@@ -351,6 +351,7 @@
 {
 	const char *	tmp_resolv_conf = RESOLV_CONF ".tmp";
 	char *		searches = NULL;
+	char *		nameservers = NULL;
 	FILE *		f;
 
 	/* If no config, we don't have anything to update, so exit silently */
@@ -364,41 +365,47 @@
 		return TRUE;
 	}
 
-	if ((f = fopen (tmp_resolv_conf, "w")) == NULL)
-		goto lose;
-
-	if (fprintf (f, "%s","# generated by NetworkManager, do not edit!\n\n") < 0)
-		goto lose;
-
 	searches = compute_searches (mgr, config);
+	nameservers = compute_nameservers (mgr, config);
 
-	if (mgr->priv->use_named == TRUE)
+	if (strlen(nameservers) > 0)
 	{
-		/* Using caching-nameserver & local DNS */
-		if (fprintf (f, "%s%s%s", "; Use a local caching nameserver controlled by NetworkManager\n\n", searches, "\nnameserver 127.0.0.1\n") < 0)
+		if ((f = fopen (tmp_resolv_conf, "w")) == NULL)
 			goto lose;
-	}
-	else
-	{
-		/* Using glibc resolver */
-		char *nameservers = compute_nameservers (mgr, config);
 
-		fprintf (f, "%s\n\n", searches);
-		g_free (searches);
+		if (fprintf (f, "%s","# generated by NetworkManager, do not edit!\n\n") < 0)
+			goto lose;
 
-		fprintf (f, "%s\n\n", nameservers);
-		g_free (nameservers);
-	}
+		if (mgr->priv->use_named == TRUE)
+		{
+			/* Using caching-nameserver & local DNS */
+			if (fprintf (f, "%s%s%s", "; Use a local caching nameserver controlled by NetworkManager\n\n", searches, "\nnameserver 127.0.0.1\n") < 0)
+				goto lose;
+		}
+		else
+		{
+			/* Using glibc resolver */
 
-	if (fclose (f) < 0)
-		goto lose;
+			fprintf (f, "%s\n\n", searches);
+			fprintf (f, "%s\n\n", nameservers);
+		}
 
-	if (rename (tmp_resolv_conf, RESOLV_CONF) < 0)
-		goto lose;
+		if (fclose (f) < 0)
+			goto lose;
+
+		if (rename (tmp_resolv_conf, RESOLV_CONF) < 0)
+			goto lose;
+	}
+	else
+		nm_info ("No name servers returned by DHCP! Leaving resolv.conf intact!");
+
+	g_free (nameservers);
+	g_free (searches);
 	nm_system_update_dns ();
 	return TRUE;
 
 lose:
+	g_free (nameservers);
 	g_free (searches);
 	fclose (f);
 	g_set_error (error,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]