Add warning for using connection block variables after connection blocks
PATCH 1/1 Add warning for using connection block variables after connection blocks
In 2.3 some options that were allowed only in global config before have been moved to connection blocks. This changes the behaviour if the variables were defined after connection block. This patch adds a warning to catch these mistakes.
--- src/openvpn/common.h | 5 +++++ src/openvpn/options.c | 34 +++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-)
src/openvpn/common.h +5 -0
@@ -98,6 +98,11 @@ typedef unsigned long ptr_type;#define INLINE_FILE_TAG "[[INLINE]]"/* +* Pseudo filename for connection blocks +*/ +#define CONNECTION_FILE_TAG "[CONNECTION-OPTIONS]" + +/* * Script security warning */ #define SCRIPT_SECURITY_WARNING "WARNING: External program may not be called unless '--script-security 2' or higher is enabled. See --help text or man page for detailed info."
src/openvpn/options.c +25 -9
@@ -3465,7 +3465,7 @@ int parse_line (const char *line, char *p[], const int n, - const char *file, +const char *file, const int line_num, int msglevel, struct gc_arena *gc)
@@ -3805,7 +3805,7 @@ read_config_string (const char *prefix, {bypass_doubledash (&p[0 ]);check_inline_file_via_buf (&multiline, p, &options->gc); -add_option (options, p,NULL , line_num,0 , msglevel, permission_mask, option_types_found, es); +add_option (options, p, prefix, line_num,0 , msglevel, permission_mask, option_types_found, es); }CLEAR (p); }
@@ -3925,27 +3925,43 @@ void options_string_import (struct options *options,#if P2MP -#define VERIFY_PERMISSION (mask) { if (!verify_permission(p[0], file, (mask), permission_mask, option_types_found, msglevel)) goto err; } +#define VERIFY_PERMISSION (mask) { if (!verify_permission(p[0], file, line, (mask), permission_mask, option_types_found, msglevel, options)) goto err; }static bool verify_permission (const char *name,const char * file, +int line,const unsigned int type,const unsigned int allowed,unsigned int *found, -const int msglevel) +const int msglevel, +struct options * options) {if (!(type & allowed)) {msg (msglevel,"option '%s' cannot be used in this context (%s)" , name, file);return false; } -else + +if (found) + *found |= type; + +#ifndef ENABLE_SMALL +/* Check if this options is allowed in connection block, +* but we are currently not in a connection block +* Parsing a connection block uses a temporary options struct without +* connection_list +*/ + +if ((type &OPT_P_CONNECTION ) && options->connection_list) { -if (found) - *found |= type; -return true; +if (file) +msg (M_WARN ,"Option '%s' in %s:%d is ignored by previous <connection> blocks " , name, file, line); +else +msg (M_WARN ,"Option '%s' is ignored by previous <connection> blocks" , name); } +#endif +return true; }#else
@@ -4377,7 +4393,7 @@ add_option (struct options *options,init_options (&sub, true); sub.ce = options->ce; -read_config_string ("[CONNECTION-OPTIONS]" , &sub, p[2 ], msglevel,OPT_P_CONNECTION , option_types_found, es); +read_config_string (CONNECTION_FILE_TAG , &sub, p[2 ], msglevel,OPT_P_CONNECTION , option_types_found, es);if (!sub.ce.remote) {msg (msglevel,"Each 'connection' block must contain exactly one 'remote' directive" );
Signature · 1 line
1.8.3.4 (Apple Git-47)
Hi,
Quoted 2 lines · Arne Schwabe
In 2.3 some options that were allowed only in global config before have been moved to connection blocks. This changes the behaviour if the variables were defined after connection block. This patch adds a warning to catch these mistakes.
---
Basically, I'm OK with that, just a few things...
src/openvpn/common.h typedef unsigned long ptr_type; · line 104
Quoted 12 lines
src/openvpn/common.h +4
-0@@ -98,6 +98,11 @@ typedef unsigned long ptr_type;#define INLINE_FILE_TAG "[[INLINE]]"/* +* Pseudo filename for connection blocks +*/ +#define CONNECTION_FILE_TAG "[CONNECTION-OPTIONS]" +
... as this is only referenced once, is it really worth adding a #define which is about as long as the string it's replacing?
Quoted 9 lines
src/openvpn/common.h +1
-0+/* * Script security warning */ #define SCRIPT_SECURITY_WARNING "WARNING: External program may not be called unless '--script-security 2' or higher is enabled. See --help text or man page for detailed info."src/openvpn/options.c +0
-0
src/openvpn/options.c int · line 3468
Quoted 5 lines
src/openvpn/options.c +1
-1@@ -3465,7 +3465,7 @@ int parse_line (const char *line, char *p[], const int n, - const char *file, +const char *file,
Yeah, whitespace :-) (I can fix that).
src/openvpn/options.c read_config_string (const char *prefix, · line 3809
Quoted 10 lines
src/openvpn/options.c +1
-1const int line_num, int msglevel, struct gc_arena *gc)@@ -3805,7 +3805,7 @@ read_config_string (const char *prefix, {bypass_doubledash (&p[0 ]);check_inline_file_via_buf (&multiline, p, &options->gc); -add_option (options, p,NULL , line_num,0 , msglevel, permission_mask, option_types_found, es); +add_option (options, p, prefix, line_num,0 , msglevel, permission_mask, option_types_found, es); }
Is that "NULL" a generic oversight? It doesn't seem like it's needed for the new functionality, more like "it should have been like that",
right? (Ah, I can see it now, we want it to not print "[CMD-LINE]"
for these cases, right?)
Quoted 40 lines
src/openvpn/options.c +16
-4CLEAR (p); }@@ -3925,27 +3925,43 @@ void options_string_import (struct options *options,#if P2MP -#define VERIFY_PERMISSION (mask) { if (!verify_permission(p[0], file, (mask), permission_mask, option_types_found, msglevel)) goto err; } +#define VERIFY_PERMISSION (mask) { if (!verify_permission(p[0], file, line, (mask), permission_mask, option_types_found, msglevel, options)) goto err; }static bool verify_permission (const char *name,const char * file, +int line,const unsigned int type,const unsigned int allowed,unsigned int *found, -const int msglevel) +const int msglevel, +struct options * options) {if (!(type & allowed)) {msg (msglevel,"option '%s' cannot be used in this context (%s)" , name, file);return false; } -else + +if (found) + *found |= type; + +#ifndef ENABLE_SMALL +/* Check if this options is allowed in connection block, +* but we are currently not in a connection block +* Parsing a connection block uses a temporary options struct without +* connection_list +*/ + +if ((type &OPT_P_CONNECTION ) && options->connection_list) { -if (found)
src/openvpn/options.c void options_string_import (struct options *options, · line 3965
Quoted 10 lines
src/openvpn/options.c +6
-2- *found |= type; -return true; +if (file) +msg (M_WARN ,"Option '%s' in %s:%d is ignored by previous <connection> blocks " , name, file, line); +else + msg (M_WARN, "Option '%s' is ignored by previous <connection> blocks", name); } +#endif +return true; }
OK :-)
(This is actually not changing the "if (*found)..." logic, it just looks that way due to the way git diff sometimes produces patches where whitespace changes close to code additions...)
src/openvpn/options.c add_option (struct options *options, · line 4399
Quoted 10 lines
src/openvpn/options.c +1
-1#else @@ -4377,7 +4393,7 @@ add_option (struct options *options,init_options (&sub, true); sub.ce = options->ce; -read_config_string ("[CONNECTION-OPTIONS]" , &sub, p[2 ], msglevel,OPT_P_CONNECTION , option_types_found, es); +read_config_string (CONNECTION_FILE_TAG , &sub, p[2 ], msglevel,OPT_P_CONNECTION , option_types_found, es);if (!sub.ce.remote) {msg (msglevel,"Each 'connection' block must contain exactly one 'remote' directive" );
... see above...
gert
Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany [email protected]...
fax: +49-89-35655025 [email protected]...Am 16.12.13 21:59, schrieb Gert Doering:
Quoted 14 lines
Hi,
Quoted 2 lines · Arne Schwabe
In 2.3 some options that were allowed only in global config before have been moved to connection blocks. This changes the behaviour if the variables were defined after connection block. This patch adds a warning to catch these mistakes.
---Basically, I'm OK with that, just a few things...
Quoted 7 lines
src/openvpn/common.h +0
-0@@ -98,6 +98,11 @@ typedef unsigned long ptr_type;#define INLINE_FILE_TAG "[[INLINE]]"
Quoted 8 lines
src/openvpn/common.h typedef unsigned long ptr_type; · line 104
Quoted 5 lines
src/openvpn/common.h +4
-0/* +* Pseudo filename for connection blocks +*/ +#define CONNECTION_FILE_TAG "[CONNECTION-OPTIONS]" +... as this is only referenced once, is it really worth adding a #define which is about as long as the string it's replacing?
Yeah. I thought it would be nice for consistency with the other special file name
Quoted 6 lines
Quoted 6 lines
src/openvpn/common.h +0
-0const int line_num, int msglevel, struct gc_arena *gc)@@ -3805,7 +3805,7 @@ read_config_string (const char *prefix, {bypass_doubledash (&p[0 ]);
Quoted 8 lines
src/openvpn/common.h read_config_string (const char *prefix, · line 3809
Quoted 4 lines
src/openvpn/common.h +1
-1check_inline_file_via_buf (&multiline, p, &options->gc); -add_option (options, p,NULL , line_num,0 , msglevel, permission_mask, option_types_found, es); +add_option (options, p, prefix, line_num,0 , msglevel, permission_mask, option_types_found, es); }Is that "NULL" a generic oversight? It doesn't seem like it's needed for the new functionality, more like "it should have been like that",
right? (Ah, I can see it now, we want it to not print "[CMD-LINE]"
for these cases, right?)
Yeah. We print CMD-LINE there which is more confusing then helping. And this function is only called by connection blocks and configs returned by plugins. So it should be save to fix it.
Quoted 53 lines
Quoted 41 lines
src/openvpn/common.h +16
-4CLEAR (p); }@@ -3925,27 +3925,43 @@ void options_string_import (struct options *options,#if P2MP -#define VERIFY_PERMISSION (mask) { if (!verify_permission(p[0], file, (mask), permission_mask, option_types_found, msglevel)) goto err; } +#define VERIFY_PERMISSION (mask) { if (!verify_permission(p[0], file, line, (mask), permission_mask, option_types_found, msglevel, options)) goto err; }static bool verify_permission (const char *name,const char * file, +int line,const unsigned int type,const unsigned int allowed,unsigned int *found, -const int msglevel) +const int msglevel, +struct options * options) {if (!(type & allowed)) {msg (msglevel,"option '%s' cannot be used in this context (%s)" , name, file);return false; } -else + +if (found) + *found |= type; + +#ifndef ENABLE_SMALL +/* Check if this options is allowed in connection block, +* but we are currently not in a connection block +* Parsing a connection block uses a temporary options struct without +* connection_list +*/ + +if ((type &OPT_P_CONNECTION ) && options->connection_list) { -if (found)src/openvpn/common.h void options_string_import (struct options *options, · line 3965
Quoted 10 lines
src/openvpn/common.h +6
-2- *found |= type; -return true; +if (file) +msg (M_WARN ,"Option '%s' in %s:%d is ignored by previous <connection> blocks " , name, file, line); +else + msg (M_WARN, "Option '%s' is ignored by previous <connection> blocks", name); } +#endif +return true; }OK :-)
Quoted 3 lines
(This is actually not changing the "if (*found)..." logic, it just looks that way due to the way git diff sometimes produces patches where whitespace changes close to code additions...)
:-)
Arne
PATCH v2 1/1 Add warning for using connection block variables after connection blocks
In reply to Arne SchwabeIn 2.3 some options that were allowed only in global config before have been moved to connection blocks. This changes the behaviour if the variables were defined after connection block. This patch adds a warning to catch these mistakes.
Also let warnings errors show [CONNECTION-OPTIONS] instead of [CMD-LINE] for connection blocks
--- src/openvpn/options.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-)
src/openvpn/options.c +23 -7
@@ -3838,7 +3838,7 @@ read_config_string (const char *prefix, {bypass_doubledash (&p[0 ]);check_inline_file_via_buf (&multiline, p, &options->gc); -add_option (options, p,NULL , line_num,0 , msglevel, permission_mask, option_types_found, es); +add_option (options, p, prefix, line_num,0 , msglevel, permission_mask, option_types_found, es); }CLEAR (p); }
@@ -3958,27 +3958,43 @@ void options_string_import (struct options *options,#if P2MP -#define VERIFY_PERMISSION (mask) { if (!verify_permission(p[0], file, (mask), permission_mask, option_types_found, msglevel)) goto err; } +#define VERIFY_PERMISSION (mask) { if (!verify_permission(p[0], file, line, (mask), permission_mask, option_types_found, msglevel, options)) goto err; }static bool verify_permission (const char *name,const char * file, +int line,const unsigned int type,const unsigned int allowed,unsigned int *found, -const int msglevel) +const int msglevel, +struct options * options) {if (!(type & allowed)) {msg (msglevel,"option '%s' cannot be used in this context (%s)" , name, file);return false; } -else + +if (found) + *found |= type; + +#ifndef ENABLE_SMALL +/* Check if this options is allowed in connection block, +* but we are currently not in a connection block +* Parsing a connection block uses a temporary options struct without +* connection_list +*/ + +if ((type &OPT_P_CONNECTION ) && options->connection_list) { -if (found) - *found |= type; -return true; +if (file) +msg (M_WARN ,"Option '%s' in %s:%d is ignored by previous <connection> blocks " , name, file, line); +else +msg (M_WARN ,"Option '%s' is ignored by previous <connection> blocks" , name); } +#endif +return true; }#else
Signature · 1 line
1.8.3.4 (Apple Git-47)
ACK. Feature-ACK was agreed in Munich already, Code-ACK on v2 by me.
Patch has been applied to the master and release/2.3 branches.
commit cd6555e0159987ef264789f4976053ce2aa5fc20 (master) commit d931524fad9aebc2de1acf4fe66ac594b30e33ef (master)
Author: Arne Schwabe Date: Tue Dec 17 11:22:47 2013 +0100
Add warning for using connection block variables after connection blocks
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/8117
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering