From patchwork Thu May 26 15:24:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Hund X-Patchwork-Id: 2493 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director13.mail.ord1d.rsapps.net ([172.31.255.6]) by backend41.mail.ord1d.rsapps.net with LMTP id aPFoEMAokGLGRgAAqwncew (envelope-from ) for ; Thu, 26 May 2022 21:26:24 -0400 Received: from proxy11.mail.iad3b.rsapps.net ([172.31.255.6]) by director13.mail.ord1d.rsapps.net with LMTP id qJi8L8AokGKnBQAA91zNiA (envelope-from ) for ; Thu, 26 May 2022 21:26:24 -0400 Received: from smtp11.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy11.mail.iad3b.rsapps.net with LMTPS id xO6wKMAokGLzMwAARNREpw (envelope-from ) for ; Thu, 26 May 2022 21:26:24 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp11.gate.iad3b.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dmarc=none (p=nil; dis=none) header.from=ist.eigentlich.net X-Suspicious-Flag: YES X-Classification-ID: 051f4cf8-dd5c-11ec-be8a-52540070b5bb-1-1 Received: from [216.105.38.7] ([216.105.38.7:59438] helo=lists.sourceforge.net) by smtp11.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 62/95-01989-FB820926; Thu, 26 May 2022 21:26:24 -0400 Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.94.2) (envelope-from ) id 1nuOjE-00034P-31; Fri, 27 May 2022 01:25:22 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nuOjD-00034D-CY for openvpn-devel@lists.sourceforge.net; Fri, 27 May 2022 01:25:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=E0kCxEhnPjq4fLaMQt/I10LrXSoZvInn6BWO7raAQ+A=; b=MSPhOI1d9Sg+sF6xFxiKtPzELo Vn4o0V94BtGKVbkZkWn9Bp6sIwUD8U0cBB9d1SmjDr0YbmD4thJm0YqwFnGFfsB0WDluUDrQn15TH wK+nhyAEkyaNUKRVLt0BBvYjufGVLkoBRAK/AfyrBCQYfDgp21G+dfR6+On/ww9Xp/vI=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=E0kCxEhnPjq4fLaMQt/I10LrXSoZvInn6BWO7raAQ+A=; b=ToAp3LBCj1nZSgwTqLixtogxSN aHbSi/Fdyh5TWwAVnCEvaO5eAtLKvGIf7805Ma/Zp0P6hYWneVPWa6N2ZLfJxdtyfK7XK54+bCbCz c89MH3oDAlWRgJv8bPJYxfK35jBGbTVqvG/GZ6f7HkOSx0qF+t2WKj7Nbb7cbdOa7l60=; Received: from exit0.net ([85.25.119.185]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.94.2) id 1nuOj6-00037b-UG for openvpn-devel@lists.sourceforge.net; Fri, 27 May 2022 01:25:21 +0000 Received: from coruscant.fritz.box (unknown [87.123.247.142]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by exit0.net (Postfix) with ESMTPSA id DF2C96480277 for ; Fri, 27 May 2022 03:25:07 +0200 (CEST) From: Heiko Hund To: openvpn-devel@lists.sourceforge.net Date: Fri, 27 May 2022 03:24:56 +0200 Message-Id: <20220527012457.1819262-4-heiko@ist.eigentlich.net> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220527012457.1819262-1-heiko@ist.eigentlich.net> References: <20220527012457.1819262-1-heiko@ist.eigentlich.net> MIME-Version: 1.0 X-Spam-Report: Spam detection software, running on the system "util-spamd-2.v13.lw.sourceforge.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add setenv_ prefix to foreign_option funtion so it is more obvious what it does. Move it further up within options.c, so it is defined before all future callers. Also declare all argv strings const. Signed-off-by: Heiko Hund --- src/openvpn/options.c | 78 +++++++++++++++++++++ 1 file changed, 39 insertions(+), 39 deletions(-) Content analysis details: (0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Headers-End: 1nuOj6-00037b-UG Subject: [Openvpn-devel] [PATCH 3/4] rename foreign_option() and move it up X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox Add setenv_ prefix to foreign_option funtion so it is more obvious what it does. Move it further up within options.c, so it is defined before all future callers. Also declare all argv strings const. Signed-off-by: Heiko Hund Acked-by: Gert Doering --- src/openvpn/options.c | 78 +++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/openvpn/options.c b/src/openvpn/options.c index bc3fd6a2..9a0634a5 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -1013,6 +1013,44 @@ setenv_settings(struct env_set *es, const struct options *o) } } +static void +setenv_foreign_option(struct options *o, const char *argv[], int len, struct env_set *es) +{ + if (len > 0) + { + struct gc_arena gc = gc_new(); + struct buffer name = alloc_buf_gc(OPTION_PARM_SIZE, &gc); + struct buffer value = alloc_buf_gc(OPTION_PARM_SIZE, &gc); + int i; + bool first = true; + bool good = true; + + good &= buf_printf(&name, "foreign_option_%d", o->foreign_option_index + 1); + ++o->foreign_option_index; + for (i = 0; i < len; ++i) + { + if (argv[i]) + { + if (!first) + { + good &= buf_printf(&value, " "); + } + good &= buf_printf(&value, "%s", argv[i]); + first = false; + } + } + if (good) + { + setenv_str(es, BSTR(&name), BSTR(&value)); + } + else + { + msg(M_WARN, "foreign_option: name/value overflow"); + } + gc_free(&gc); + } +} + static in_addr_t get_ip_addr(const char *ip_string, int msglevel, bool *error) { @@ -4378,44 +4416,6 @@ options_string_extract_option(const char *options_string, const char *opt_name, return ret; } -static void -foreign_option(struct options *o, char *argv[], int len, struct env_set *es) -{ - if (len > 0) - { - struct gc_arena gc = gc_new(); - struct buffer name = alloc_buf_gc(OPTION_PARM_SIZE, &gc); - struct buffer value = alloc_buf_gc(OPTION_PARM_SIZE, &gc); - int i; - bool first = true; - bool good = true; - - good &= buf_printf(&name, "foreign_option_%d", o->foreign_option_index + 1); - ++o->foreign_option_index; - for (i = 0; i < len; ++i) - { - if (argv[i]) - { - if (!first) - { - good &= buf_printf(&value, " "); - } - good &= buf_printf(&value, "%s", argv[i]); - first = false; - } - } - if (good) - { - setenv_str(es, BSTR(&name), BSTR(&value)); - } - else - { - msg(M_WARN, "foreign_option: name/value overflow"); - } - gc_free(&gc); - } -} - #ifdef _WIN32 /** * Parses --windows-driver config option @@ -8014,7 +8014,7 @@ add_option(struct options *options, else if (streq(p[0], "dhcp-option") && p[1] && !p[3]) { VERIFY_PERMISSION(OPT_P_IPWIN32); - foreign_option(options, p, 3, es); + setenv_foreign_option(options, (const char **)p, 3, es); } else if (streq(p[0], "route-method") && p[1] && !p[2]) /* ignore when pushed to non-Windows OS */ {