summary refs log tree commit diff
path: root/debian/patches/07-domain_search.patch
blob: cf614a0d0597db59480ec5f7433a3d5e8775b6b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
Index: NetworkManager-0.6/src/dhcp-manager/nm-dhcp-manager.c
===================================================================
--- NetworkManager-0.6.orig/src/dhcp-manager/nm-dhcp-manager.c	2008-03-02 09:25:16.000000000 +0100
+++ NetworkManager-0.6/src/dhcp-manager/nm-dhcp-manager.c	2008-03-02 09:26:33.000000000 +0100
@@ -472,6 +472,7 @@
 	guint32		num_ip4_nis_servers = 0;
 	char *		hostname = NULL;
 	char *		domain_names = NULL;
+	char *		domain_searches = NULL;
 	char *		nis_domain = NULL;
 	guint32 *		ip4_nis_servers = NULL;
 	struct in_addr	temp_addr;
@@ -520,6 +521,7 @@
 	get_ip4_string (manager, dev, "host_name", &hostname, TRUE);
 	get_ip4_uint32s (manager, dev, "domain_name_servers", &ip4_nameservers, &num_ip4_nameservers, FALSE);
 	get_ip4_string (manager, dev, "domain_name", &domain_names, TRUE);
+	get_ip4_string (manager, dev, "domain_search", &domain_searches, TRUE);
 	get_ip4_string (manager, dev, "nis_domain", &nis_domain, TRUE);
 	get_ip4_uint32s (manager, dev, "nis_servers", &ip4_nis_servers, &num_ip4_nis_servers, TRUE);
 
@@ -557,14 +559,27 @@
 
 	if (domain_names)
 	{
-		char **searches = g_strsplit (domain_names, " ", 0);
+		char **domains = g_strsplit (domain_names, " ", 0);
 		char **s;
 
-		for (s = searches; *s; s++)
+		for (s = domains; *s; s++)
 		{
 			nm_info ("  domain name '%s'", *s);
 			nm_ip4_config_add_domain (ip4_config, *s);
 		}
+		g_strfreev (domains);
+	}
+
+	if (domain_searches)
+	{
+		char **searches = g_strsplit (domain_searches, " ", 0);
+		char **s;
+
+		for (s = searches; *s; s++)
+		{
+			nm_info ("  domain search '%s'", *s);
+			nm_ip4_config_add_search (ip4_config, *s);
+		}
 		g_strfreev (searches);
 	}
 
Index: NetworkManager-0.6/src/named-manager/nm-named-manager.c
===================================================================
--- NetworkManager-0.6.orig/src/named-manager/nm-named-manager.c	2008-03-02 09:25:16.000000000 +0100
+++ NetworkManager-0.6/src/named-manager/nm-named-manager.c	2008-03-02 09:26:33.000000000 +0100
@@ -319,7 +319,7 @@
 static char *
 compute_searches (NMNamedManager *mgr, NMIP4Config *config)
 {
-	int i, num_searches;
+	int i, num_searches, num_domains;
 	GString *str = NULL;
 
 	g_return_val_if_fail (mgr != NULL, g_strdup (""));
@@ -328,14 +328,54 @@
 	if (!config)
 		return g_strdup ("");
 
-	num_searches = nm_ip4_config_get_num_domains (config);
-	for (i = 0; i < num_searches; i++)
-	{
-		if (!str)
-			str = g_string_new ("search");
+	num_searches = nm_ip4_config_get_num_searches (config);
+	num_domains  = nm_ip4_config_get_num_domains  (config);
+
+	/* ISC DHCP 3.1 provides support for the domain-search option. This is the
+	 * correct way for a DHCP server to provide a domain search list. Wedging
+	 * multiple domains into the domain-name option is a horrible hack.
+	 *
+	 * So, we handle it like this (as proposed by Andrew Pollock at
+	 * http://bugs.debian.org/465158):
+	 *
+	 * - if the domain-search option is present in the data received via DHCP,
+	 *   use it in favour of the domain-name option for setting the search
+	 *   directive in /etc/resolv.conf
+	 *
+	 * - if the domain-name option is present in the data received via DHCP, use
+	 *   it to set the domain directive in /etc/resolv.conf
+	 *   (this is handled in compute_domain() below)
+	 *
+	 * - if only the domain-name option is present in the data received via DHCP
+	 *   (and domain-search is not), for backwards compatibility, set the search
+	 *   directive in /etc/resolv.conf to the specified domain names
+	 */
 
-		g_string_append_c (str, ' ');
-		g_string_append (str, nm_ip4_config_get_domain (config, i));		
+	if ( num_searches == 0 && num_domains > 0 )
+	{
+		/* old, pre-ISC-3.1 fallback:
+		 * use (possibly multiple entries from) domain-name for the search entry */
+		str = g_string_new ("search");
+		for (i = 0; i < num_domains; i++)
+		{
+			g_string_append_c (str, ' ');
+			g_string_append (str, nm_ip4_config_get_domain (config, i));
+		}
+	}
+	else if ( num_searches > 0 )
+	{
+		/* the "correct", post-ISC-3.1 situation: use searches just as received */
+		str = g_string_new ("search");
+		for (i = 0; i < num_searches; i++)
+		{
+			g_string_append_c (str, ' ');
+			g_string_append (str, nm_ip4_config_get_search (config, i));
+		}
+	}
+	else /* num_searches == 0 && num_domains == 0 */
+	{
+		/* no info available at all */
+		return g_strdup ("");
 	}
 
 	if (!str)
@@ -346,11 +386,41 @@
 	return g_string_free (str, FALSE);
 }
 
+static char *
+compute_domain (NMNamedManager *mgr, NMIP4Config *config)
+{
+	int num_domains;
+	GString *str = NULL;
+
+	g_return_val_if_fail (mgr != NULL, g_strdup (""));
+
+	/* config can be NULL */
+	if (!config)
+		return g_strdup ("");
+
+	num_domains = nm_ip4_config_get_num_domains (config);
+
+	/* warn the user that he should change his config
+	 * (see comments above in compute_search() ) */
+	if ( num_domains > 1 )
+		nm_warning ("DHCP server sent multiple entries in domain-name; this is obsolete behaviour; please fix or update your DHCP server");
+
+	if (num_domains == 0)
+		return g_strdup ("");
+
+	str = g_string_new ("domain ");
+	g_string_append (str, nm_ip4_config_get_domain (config, 0));
+	g_string_append_c (str, '\n');
+
+	return g_string_free (str, FALSE);
+}
+
 static gboolean
 rewrite_resolv_conf (NMNamedManager *mgr, NMIP4Config *config, GError **error)
 {
 	const char *	tmp_resolv_conf = RESOLV_CONF ".tmp";
 	char *		searches = NULL;
+	char *		domain   = NULL;
 	FILE *		f;
 	NMIP4Config *ns_config = config;
 
@@ -388,23 +458,27 @@
 	}
 	g_return_val_if_fail (ns_config != NULL, FALSE);
 
+	domain   = compute_domain   (mgr, ns_config);
 	searches = compute_searches (mgr, ns_config);
 
 	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)
+		if (fprintf (f, "%s%s%s%s", "; Use a local caching nameserver controlled by NetworkManager\n\n", domain, searches, "\nnameserver 127.0.0.1\n") < 0)
 			goto lose;
 	} else {
 		/* Using glibc resolver */
 		char *nameservers = compute_nameservers (mgr, ns_config);
 
+		fprintf (f, "%s\n\n", domain);
 		fprintf (f, "%s\n\n", searches);
-		g_free (searches);
-
 		fprintf (f, "%s\n\n", nameservers);
+
 		g_free (nameservers);
 	}
 
+	g_free (domain);
+	g_free (searches);
+
 	if (fclose (f) < 0)
 		goto lose;
 
@@ -414,6 +488,7 @@
 	return TRUE;
 
 lose:
+	g_free (domain);
 	g_free (searches);
 	fclose (f);
 	g_set_error (error,
Index: NetworkManager-0.6/src/nm-ip4-config.c
===================================================================
--- NetworkManager-0.6.orig/src/nm-ip4-config.c	2008-03-02 09:25:16.000000000 +0100
+++ NetworkManager-0.6/src/nm-ip4-config.c	2008-03-02 09:26:33.000000000 +0100
@@ -46,6 +46,7 @@
 
 	GSList *	nameservers;
 	GSList *	domains;
+	GSList *	searches;
 
 	gchar *	hostname;
 	gchar *	nis_domain;
@@ -275,6 +276,17 @@
 	config->domains = g_slist_append (config->domains, g_strdup (domain));
 }
 
+void nm_ip4_config_add_search (NMIP4Config *config, const char *search)
+{
+	g_return_if_fail (config != NULL);
+	g_return_if_fail (search != NULL);
+
+	if (!strlen (search))
+		return;
+
+	config->searches = g_slist_append (config->searches, g_strdup (search));
+}
+
 void nm_ip4_config_set_hostname (NMIP4Config *config, const char *hostname)
 {
 	g_return_if_fail (config != NULL);
@@ -329,6 +341,25 @@
 	return (g_slist_length (config->domains));
 }
 
+const char *nm_ip4_config_get_search (NMIP4Config *config, guint i)
+{
+	const char *search;
+
+	g_return_val_if_fail (config != NULL, NULL);
+	g_return_val_if_fail (i < g_slist_length (config->searches), NULL);
+
+	if ((search = (const char *) g_slist_nth_data (config->searches, i)))
+		return search;
+	return NULL;
+}
+
+guint32 nm_ip4_config_get_num_searches (NMIP4Config *config)
+{
+	g_return_val_if_fail (config != NULL, 0);
+
+	return (g_slist_length (config->searches));
+}
+
 guint32 nm_ip4_config_get_mtu (NMIP4Config *config)
 {
 	g_return_val_if_fail (config != NULL, 0);
Index: NetworkManager-0.6/src/nm-ip4-config.h
===================================================================
--- NetworkManager-0.6.orig/src/nm-ip4-config.h	2008-03-02 09:25:16.000000000 +0100
+++ NetworkManager-0.6/src/nm-ip4-config.h	2008-03-02 09:26:33.000000000 +0100
@@ -68,6 +68,14 @@
 const char *	nm_ip4_config_get_domain			(NMIP4Config *config, guint i);
 guint32		nm_ip4_config_get_num_domains		(NMIP4Config *config);
 
+void			nm_ip4_config_add_search			(NMIP4Config *config, const char *search);
+const char *	nm_ip4_config_get_search			(NMIP4Config *config, guint i);
+guint32		nm_ip4_config_get_num_searches		(NMIP4Config *config);
+
+void			nm_ip4_config_add_domain			(NMIP4Config *config, const char *search);
+const char *	nm_ip4_config_get_domain			(NMIP4Config *config, guint i);
+guint32		nm_ip4_config_get_num_searches		(NMIP4Config *config);
+
 guint32		nm_ip4_config_get_mtu			(NMIP4Config *config);
 void			nm_ip4_config_set_mtu			(NMIP4Config *config, guint32 mtu);