From: "cron2 (Code Review)" Date: Sat, 28 Jun 2025 16:22:48 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., heiko@...515..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <7ba4b5dd55873d4be225e3fbb8b3639c51e36578-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="OJRZER5tEcQ="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: run forced --dns-updown without --script-security List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: d12fk Cc: flichtenheld , plaisthos , openvpn-devel --OJRZER5tEcQ= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/10= 65?usp=3Demail ) Change subject: run forced --dns-updown without --script-security ...................................................................... run forced --dns-updown without --script-security Due to a shortcut in the `--dns-updown force' implementation, running the default dns-updown script required `--script-security 2'. This makes the forced default script run without --script-security set. Change-Id: I55940b78e35f0e3d74aa6cba14378afed97a444e Signed-off-by: Heiko Hund Acked-by: Frank Lichtenheld Message-Id: <20250626093006.24789-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg31= 994.html Signed-off-by: Gert Doering --- M src/openvpn/dns.c M src/openvpn/dns.h M src/openvpn/options.c 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/openvpn/dns.c b/src/openvpn/dns.c index 939ae09..ea3d91b 100644 --- a/src/openvpn/dns.c +++ b/src/openvpn/dns.c @@ -264,7 +264,7 @@ clone.servers =3D clone_dns_servers(o->servers, gc); clone.servers_prepull =3D clone_dns_servers(o->servers_prepull, gc); clone.updown =3D o->updown; - clone.user_set_updown =3D o->user_set_updown; + clone.updown_flags =3D o->updown_flags; return clone; } @@ -580,7 +580,7 @@ argv_printf(&argv, "%s", o->updown); argv_msg(M_INFO, &argv); int res; - if (o->user_set_updown) + if (dns_updown_user_set(o)) { res =3D openvpn_run_script(&argv, es, S_EXITCODE, "dns updown"); } @@ -692,7 +692,7 @@ run_up_down_command(bool up, struct options *o, const struct tuntap *tt, s= truct dns_updown_runner_info *updown_runner) { struct dns_options *dns =3D &o->dns_options; - if (!dns->updown || (o->up_script && !dns->user_set_updown)) + if (!dns->updown || (o->up_script && !dns_updown_user_set(dns) && !dns= _updown_forced(dns))) { return; } diff --git a/src/openvpn/dns.h b/src/openvpn/dns.h index 688daa7..d33f64e 100644 --- a/src/openvpn/dns.h +++ b/src/openvpn/dns.h @@ -42,13 +42,18 @@ DNS_TRANSPORT_TLS }; +enum dns_updown_flags { + DNS_UPDOWN_NO_FLAGS, + DNS_UPDOWN_USER_SET, + DNS_UPDOWN_FORCED +}; + struct dns_domain { struct dns_domain *next; const char *name; }; -struct dns_server_addr -{ +struct dns_server_addr { union { struct in_addr a4; struct in6_addr a6; @@ -103,7 +108,7 @@ struct dns_server *servers; struct gc_arena gc; const char *updown; - bool user_set_updown; + enum dns_updown_flags updown_flags; }; /** @@ -195,4 +200,26 @@ */ void show_dns_options(const struct dns_options *o); +/** + * Returns whether dns-updown is user defined + * + * @param o Pointer to the DNS options struct + */ +static inline bool +dns_updown_user_set(const struct dns_options *o) +{ + return o->updown_flags =3D=3D DNS_UPDOWN_USER_SET; +} + +/** + * Returns whether dns-updown is forced to run + * + * @param o Pointer to the DNS options struct + */ +static inline bool +dns_updown_forced(const struct dns_options *o) +{ + return o->updown_flags =3D=3D DNS_UPDOWN_FORCED; +} + #endif /* ifndef DNS_H */ diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 7e26069..af097f8 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -3593,7 +3593,7 @@ struct gc_arena gc =3D gc_new(); struct dns_options *dns =3D &o->dns_options; - if (dns->servers || dns->user_set_updown) + if (dns->servers || dns_updown_user_set(dns) || dns_updown_forced(dns)) { /* Clean up env from --dhcp-option DNS config */ struct buffer name =3D alloc_buf_gc(OPTION_PARM_SIZE, &gc); @@ -3667,7 +3667,7 @@ } } } - else if (o->up_script && !dns->user_set_updown) + else if (o->up_script && !dns_updown_user_set(dns) && !dns_updown_forc= ed(dns)) { /* Set foreign option env vars from --dns config */ const char *p[] =3D { "dhcp-option", NULL, NULL }; @@ -8182,15 +8182,15 @@ if (streq(p[1], "disable")) { dns->updown =3D NULL; - dns->user_set_updown =3D false; + dns->updown_flags =3D DNS_UPDOWN_NO_FLAGS; } else if (streq(p[1], "force")) { /* force dns-updown run, even if a --up script is defined */ - if (dns->user_set_updown =3D=3D false) + if (!dns_updown_user_set(dns)) { dns->updown =3D DEFAULT_DNS_UPDOWN; - dns->user_set_updown =3D true; + dns->updown_flags =3D DNS_UPDOWN_FORCED; } } else @@ -8201,7 +8201,7 @@ dns->updown =3D NULL; } set_user_script(options, &dns->updown, p[1], p[0], false); - dns->user_set_updown =3D true; + dns->updown_flags =3D DNS_UPDOWN_USER_SET; } } else if (streq(p[0], "dns") && p[1]) -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1065?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I55940b78e35f0e3d74aa6cba14378afed97a444e Gerrit-Change-Number: 1065 Gerrit-PatchSet: 4 Gerrit-Owner: d12fk Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: merged --OJRZER5tEcQ= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 submitted this change.

View Change

run forced --dns-updown without --script-secu=
rity

Due to a shortcut in the `--dns-updown force' implementatio= n, running the
default dns-updown script required `--script-security 2&#= 39;. This makes the
forced default script run without --script-security = set.

Change-Id: I55940b78e35f0e3d74aa6cba14378afed97a444e
Signed-= off-by: Heiko Hund <heiko@...2662...>
Acked-by: Frank Lichtenheld = <frank@...2641...>
Message-Id: <20250626093006.24789-1-gert@...493...= 1296...>
URL: https://www.mail-archive.com/openvpn-devel@...1659...= forge.net/msg31994.html
Signed-off-by: Gert Doering <gert@...1296...&= gt;
---
M src/openvpn/dns.c
M src/openvpn/dns.h
M src/openvpn/o= ptions.c
3 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/src/openvpn/dns.c b/src/openvpn/dns.c
index= 939ae09..ea3d91b 100644
--- a/src/openvpn/dns.c
= +++ b/src/openvpn/dns.c
@@ -264,7 +264,7 @@ clone.servers =3D clone_dns_servers(o->servers, gc);<= br> clone.servers_prepull =3D clone_dns_servers(o->servers_pre= pull, gc);
clone.updown =3D o->updown;
- clone.user_set_updown =3D o-&g= t;user_set_updown;
+ = clone.updown_flags =3D o->updown_flags;

<= span> return clone;
}
@@ -580,7 +580,7= @@
argv_printf(&argv, "%s", o->updow= n);
argv_msg(M_INFO, &argv);
= int res;
- if (o->= ;user_set_updown)
+ = if (dns_updown_user_set(o))
{
= res =3D openvpn_run_script(&argv, es, S_EXITCODE, "dns updown&q= uot;);
}
@@ -692,7 +692,7 @@ run_up_down_command(bool up, struct options *o, const struct tuntap= *tt, struct dns_updown_runner_info *updown_runner)
{
struct dns_options *dns =3D &o->dns_options;=
- if (!dns->updown || (= o->up_script && !dns->user_set_updown))
+ if (!dns->updown || (o->up_scri= pt && !dns_updown_user_set(dns) && !dns_updown_forced(dns))= )
{
return;
= }
diff --git a/src/openvpn/dns.h b/src/openvpn/dns.h

index 688daa7..d33f64e 100644
--- a/src/openv= pn/dns.h
+++ b/src/openvpn/dns.h
@@ -42,13 = +42,18 @@
DNS_TRANSPORT_TLS
};=

+enum dns= _updown_flags {
+ = DNS_UPDOWN_NO_FLAGS,
= + DNS_UPDOWN_USER_SET,
+ DNS_UPDOWN_FORCED
+};
+ struct dns_domain {
struct dns_domain *next;<= /span>
const char *name;
};
=
-struct dns_server_ad= dr
-{
+struct dns_server_addr {
union {

struct in_addr a4;
struct in6_addr a6;
@@ -103,7 +108,7 @@ struct dns_server *servers;
struct gc_are= na gc;
const char *updown;
- bool user_set_updown;
+ enum dns_updown_flags updown_flags;
};

/**
@= @ -195,4 +200,26 @@
*/
void show_dns_opt= ions(const struct dns_options *o);

+/**
+ * Returns whether dns-updown is user defined
<= span style=3D"color: hsl(120, 100%, 40%);">+ *

+ * @param o Pointer to the DNS optio= ns struct
+ */=
+static inline bool<= br>+dns_updown_user_set(const s= truct dns_options *o)
+{
+ return o->= ;updown_flags =3D=3D DNS_UPDOWN_USER_SET;
+}
+
+/**
<= span style=3D"color: hsl(120, 100%, 40%);">+ * Returns whether dns-updown i= s forced to run
+ *
+ * @param o = Pointer to the DNS options struct
+ */
= +static inline bool
+= dns_updown_forced(const struct dns_options *o)
+{
+ return o->updown_flags =3D=3D DNS_UPDOWN_FORCED;
= +}
+
#endif /* ifndef DNS_H */

diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index 7e26069..af097f8 100644
--- a/src/openvpn= /options.c
+++ b/src/openvpn/options.c
@@ -= 3593,7 +3593,7 @@
struct gc_arena gc =3D gc_new();

struct dns_options *dns =3D &o->dns_options;

- if (d= ns->servers || dns->user_set_updown)
+ if (dns->servers || dns_updown_user_set(dns) = || dns_updown_forced(dns))
{
= /* Clean up env from --dhcp-option DNS config */
s= truct buffer name =3D alloc_buf_gc(OPTION_PARM_SIZE, &gc);
@@ -3667,7 +3667,7 @@

}
= }
}
- else if (o->up_script && !dns->user_set_updown)=
+ else if (o->= up_script && !dns_updown_user_set(dns) && !dns_updown_force= d(dns))
{
/* Set foreign opti= on env vars from --dns config */
const char *p[] = =3D { "dhcp-option", NULL, NULL };
@@ -8182,15 +8= 182,15 @@
if (streq(p[1], "disable"))
{
dns->updown =3D NU= LL;
- dns-&g= t;user_set_updown =3D false;
+ dns->updown_flags =3D DNS_UPDOWN_NO_FLAGS; }
else if (streq(p[1], "forc= e"))
{
/* force = dns-updown run, even if a --up script is defined */
- if (dns->user_set_updown =3D= =3D false)
+ = if (!dns_updown_user_set(dns))
{
= dns->updown =3D DEFAULT_DNS_UPDOWN;
- dns->user_set_up= down =3D true;

+ = dns->updown_flags =3D DNS_UPDOWN_FORCED;
= }
}
else<= br>@@ -8201,7 +8201,7 @@
dns->upd= own =3D NULL;
}
s= et_user_script(options, &dns->updown, p[1], p[0], false);
= - dns->user_set_upd= own =3D true;
+ = dns->updown_flags =3D DNS_UPDOWN_USER_SET;
= }
}
else if (streq(p[0], "= dns") && p[1])

To view, vi= sit chan= ge 1065. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I55940b78e35f0e3d74aa6cba143= 78afed97a444e
Gerrit-Change-Number: 1065
Gerrit-PatchSet: 4
Gerrit-Owner: d12fk <heiko@...515...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: merged
--OJRZER5tEcQ=--