}
}
}
+#else /* if defined(_WIN32) || defined(TARGET_ANDROID) */
+static void
+foreign_options_copy_dns(struct options *o, struct env_set *es)
+{
+ const struct dns_domain *domain = o->dns_options.search_domains;
+ const struct dns_server *server = o->dns_options.servers;
+ if (!domain && !server)
+ {
+ return;
+ }
+
+ /* reset the index since we're starting all over again */
+ int opt_max = o->foreign_option_index;
+ o->foreign_option_index = 0;
+
+ for (int i = 1; i <= opt_max; ++i)
+ {
+ char name[32];
+ openvpn_snprintf(name, sizeof(name), "foreign_option_%d", i);
+
+ const char *env_str = env_set_get(es, name);
+ const char *value = strchr(env_str, '=') + 1;
+ if ((domain && strstr(value, "dhcp-option DOMAIN-SEARCH") == value)
+ || (server && strstr(value, "dhcp-option DNS") == value))
+ {
+ setenv_del(es, name);
+ }
+ else
+ {
+ setenv_foreign_option(o, &value, 1, es);
+ }
+ }
+
+ struct gc_arena gc = gc_new();
+
+ while (server)
+ {
+ if (server->addr4_defined)
+ {
+ const char *argv[] = {
+ "dhcp-option",
+ "DNS",
+ print_in_addr_t(server->addr4.s_addr, 0, &gc)
+ };
+ setenv_foreign_option(o, argv, 3, es);
+ }
+ if (server->addr6_defined)
+ {
+ const char *argv[] = {
+ "dhcp-option",
+ "DNS6",
+ print_in6_addr(server->addr6, 0, &gc)
+ };
+ setenv_foreign_option(o, argv, 3, es);
+ }
+ server = server->next;
+ }
+ while (domain)
+ {
+ const char *argv[] = { "dhcp-option", "DOMAIN-SEARCH", domain->name };
+ setenv_foreign_option(o, argv, 3, es);
+ domain = domain->next;
+ }
+
+ gc_free(&gc);
+
+ /* remove old leftover entries */
+ while (o->foreign_option_index < opt_max)
+ {
+ char name[32];
+ openvpn_snprintf(name, sizeof(name), "foreign_option_%d", opt_max--);
+ setenv_del(es, name);
+ }
+}
#endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */
#ifndef ENABLE_SMALL
}
static void
-options_postprocess_mutate(struct options *o)
+options_postprocess_mutate(struct options *o, struct env_set *es)
{
int i;
/*
{
dns_options_preprocess_pull(&o->dns_options);
}
-#if defined(_WIN32) || defined(TARGET_ANDROID)
else
{
+#if defined(_WIN32) || defined(TARGET_ANDROID)
tuntap_options_copy_dns(o);
- }
+#else
+ foreign_options_copy_dns(o, es);
#endif
+ }
pre_connect_save(o);
}
* options.
*/
void
-options_postprocess(struct options *options)
+options_postprocess(struct options *options, struct env_set *es)
{
- options_postprocess_mutate(options);
+ options_postprocess_mutate(options, es);
options_postprocess_verify(options);
#ifndef ENABLE_SMALL
options_postprocess_filechecks(options);
setenv_dns_options(&o->dns_options, es);
#if defined(_WIN32) || defined(TARGET_ANDROID)
tuntap_options_copy_dns(o);
+#else
+ foreign_options_copy_dns(o, es);
#endif
}
return success;