Skip to content

Commit ae90cba

Browse files
d12fkcron2
authored andcommitted
dns: support multiple domains without DHCP
Instead of using wmic on Windows to set one (the first) DNS domain, modify the registry directly and let the resolver know that something changed. This fixes that more than one search domain suffix could only be applied when DHCP and the tap driver was used. Now this works as well in netsh mode with the interactive service. If possible the search domains are stored with the rest of the VPN interface parameter values. However, a global search list and one which is distributed via group policy have priority (in that order), so we probe for the existence of those first. In order to be able to restore the original list in any case we store an "initial list" as a backup of the search list before we modify it. Github: closes #642 Change-Id: Icaffbfa6b2e8efa2bd24a05537cb74b15f4fed96 Signed-off-by: Heiko Hund <[email protected]> Acked-by: Gert Doering <[email protected]> Message-Id: <[email protected]> URL: https://www.mail-archive.com/[email protected]/msg31108.html Signed-off-by: Gert Doering <[email protected]>
1 parent ebd433b commit ae90cba

File tree

5 files changed

+717
-106
lines changed

5 files changed

+717
-106
lines changed

src/openvpn/options.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8370,7 +8370,7 @@ add_option(struct options *options,
83708370
msg(msglevel, "--dhcp-option %s: maximum of %d search entries can be specified",
83718371
p[1], N_SEARCH_LIST_LEN);
83728372
}
8373-
o->dhcp_options |= DHCP_OPTIONS_DHCP_REQUIRED;
8373+
o->dhcp_options |= DHCP_OPTIONS_DHCP_OPTIONAL;
83748374
}
83758375
else if (streq(p[1], "DISABLE-NBT") && !p[2])
83768376
{

src/openvpn/tun.c

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,10 @@ do_dns_domain_service(bool add, const struct tuntap *tt)
183183
{
184184
ack_message_t ack;
185185
struct gc_arena gc = gc_new();
186-
HANDLE pipe = tt->options.msg_channel;
186+
const struct tuntap_options *o = &tt->options;
187187

188-
if (!tt->options.domain) /* no domain to add or delete */
188+
/* no domains to add or delete */
189+
if (!o->domain && !o->domain_search_list[0])
189190
{
190191
goto out;
191192
}
@@ -203,28 +204,49 @@ do_dns_domain_service(bool add, const struct tuntap *tt)
203204
.addr_len = 0 /* add/delete only the domain, not DNS servers */
204205
};
205206

207+
/* interface name is required */
206208
strncpynt(dns.iface.name, tt->actual_name, sizeof(dns.iface.name));
207-
strncpynt(dns.domains, tt->options.domain, sizeof(dns.domains));
208-
/* truncation of domain name is not checked as it can't happen
209-
* with 512 bytes room in dns.domains.
210-
*/
211209

212-
msg(D_LOW, "%s dns domain on '%s' (if_index = %d) using service",
210+
/* only use domain when there are no search domains */
211+
if (o->domain && !o->domain_search_list[0])
212+
{
213+
strncpynt(dns.domains, o->domain, sizeof(dns.domains));
214+
}
215+
216+
/* Create a comma separated list of search domains */
217+
for (int i = 0; i < N_SEARCH_LIST_LEN && o->domain_search_list[i]; ++i)
218+
{
219+
size_t dstlen = strlen(dns.domains);
220+
size_t srclen = strlen(o->domain_search_list[i]);
221+
size_t extra = dstlen ? 2 : 1; /* space for comma and NUL */
222+
if (dstlen + srclen + extra > sizeof(dns.domains))
223+
{
224+
msg(M_WARN, "DNS search domains sent to service truncated to %d", i);
225+
break;
226+
}
227+
if (dstlen)
228+
{
229+
dns.domains[dstlen++] = ',';
230+
}
231+
strncpy(dns.domains + dstlen, o->domain_search_list[i], srclen + 1);
232+
}
233+
234+
msg(D_LOW, "%s DNS domains on '%s' (if_index = %d) using service",
213235
(add ? "Setting" : "Deleting"), dns.iface.name, dns.iface.index);
214-
if (!send_msg_iservice(pipe, &dns, sizeof(dns), &ack, "TUN"))
236+
if (!send_msg_iservice(o->msg_channel, &dns, sizeof(dns), &ack, "TUN"))
215237
{
216238
goto out;
217239
}
218240

219241
if (ack.error_number != NO_ERROR)
220242
{
221-
msg(M_WARN, "TUN: %s dns domain failed using service: %s [status=%u if_name=%s]",
243+
msg(M_WARN, "TUN: %s DNS domains failed using service: %s [status=%u if_name=%s]",
222244
(add ? "adding" : "deleting"), strerror_win32(ack.error_number, &gc),
223245
ack.error_number, dns.iface.name);
224246
goto out;
225247
}
226248

227-
msg(M_INFO, "DNS domain %s using service", (add ? "set" : "deleted"));
249+
msg(M_INFO, "DNS domains %s using service", (add ? "set" : "deleted"));
228250

229251
out:
230252
gc_free(&gc);

src/openvpnserv/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ target_compile_options(openvpnserv PRIVATE
2828
-D_WIN32_WINNT=_WIN32_WINNT_VISTA
2929
)
3030
target_link_libraries(openvpnserv
31-
advapi32.lib userenv.lib iphlpapi.lib fwpuclnt.lib rpcrt4.lib shlwapi.lib netapi32.lib ws2_32.lib ntdll.lib)
31+
advapi32.lib userenv.lib iphlpapi.lib fwpuclnt.lib rpcrt4.lib
32+
shlwapi.lib netapi32.lib ws2_32.lib ntdll.lib ole32.lib)
3233
if (MINGW)
3334
target_compile_options(openvpnserv PRIVATE -municode)
3435
target_link_options(openvpnserv PRIVATE -municode)

src/openvpnserv/Makefile.am

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ openvpnserv_CFLAGS = \
2525
-municode -D_UNICODE \
2626
-UNTDDI_VERSION -U_WIN32_WINNT \
2727
-D_WIN32_WINNT=_WIN32_WINNT_VISTA
28-
openvpnserv_LDADD = -ladvapi32 -luserenv -liphlpapi -lfwpuclnt -lrpcrt4 -lshlwapi -lnetapi32 -lws2_32 -lntdll
28+
openvpnserv_LDADD = \
29+
-ladvapi32 -luserenv -liphlpapi -lfwpuclnt -lrpcrt4 \
30+
-lshlwapi -lnetapi32 -lws2_32 -lntdll -lole32
2931
endif
3032

3133
openvpnserv_SOURCES = \

0 commit comments

Comments
 (0)