Browse code

Fix multiple configured scripts conflicts issue (version 2)

This is a fix for trac ticket #20,
<https://community.openvpn.net/openvpn/ticket/20>
which was started in the sf.net bug tracker:
<http://sourceforge.net/tracker/?func=detail&aid=2078470&group_id=48978&atid=454719>

The implemented solution is to give a warning for each of the different script hooks
available. The last configured script will override any earlier configured scripts,
to ensure that the command line can override the configuration file.

Signed-off-by: David Sommerseth <dazo@users.sourceforge.net>
Acked-by: James Yonan <james@openvpn.net>

David Sommerseth authored on 2010/08/06 03:51:22
Showing 1 changed files
... ...
@@ -3491,6 +3491,15 @@ msglevel_forward_compatible (struct options *options, const int msglevel)
3491 3491
 }
3492 3492
 
3493 3493
 static void
3494
+warn_multiple_script (const char *script, const char *type) {
3495
+      if (script) {
3496
+	msg (M_WARN, "Multiple --%s scripts defined.  "
3497
+	     "The previously configured script is overridden.", type);
3498
+      }
3499
+}
3500
+
3501
+
3502
+static void
3494 3503
 add_option (struct options *options,
3495 3504
 	    char *p[],
3496 3505
 	    const char *file,
... ...
@@ -3890,6 +3899,7 @@ add_option (struct options *options,
3890 3890
       VERIFY_PERMISSION (OPT_P_SCRIPT);
3891 3891
       if (!no_more_than_n_args (msglevel, p, 2, NM_QUOTE_HINT))
3892 3892
 	goto err;
3893
+      warn_multiple_script (options->ipchange, "ipchange");
3893 3894
       options->ipchange = string_substitute (p[1], ',', ' ', &options->gc);
3894 3895
     }
3895 3896
   else if (streq (p[0], "float"))
... ...
@@ -3936,6 +3946,7 @@ add_option (struct options *options,
3936 3936
       VERIFY_PERMISSION (OPT_P_SCRIPT);
3937 3937
       if (!no_more_than_n_args (msglevel, p, 2, NM_QUOTE_HINT))
3938 3938
 	goto err;
3939
+      warn_multiple_script (options->up_script, "up");
3939 3940
       options->up_script = p[1];
3940 3941
     }
3941 3942
   else if (streq (p[0], "down") && p[1])
... ...
@@ -3943,6 +3954,7 @@ add_option (struct options *options,
3943 3943
       VERIFY_PERMISSION (OPT_P_SCRIPT);
3944 3944
       if (!no_more_than_n_args (msglevel, p, 2, NM_QUOTE_HINT))
3945 3945
 	goto err;
3946
+      warn_multiple_script (options->down_script, "down");
3946 3947
       options->down_script = p[1];
3947 3948
     }
3948 3949
   else if (streq (p[0], "down-pre"))
... ...
@@ -4624,6 +4636,7 @@ add_option (struct options *options,
4624 4624
       VERIFY_PERMISSION (OPT_P_SCRIPT);
4625 4625
       if (!no_more_than_n_args (msglevel, p, 2, NM_QUOTE_HINT))
4626 4626
 	goto err;
4627
+      warn_multiple_script (options->route_script, "route-up");
4627 4628
       options->route_script = p[1];
4628 4629
     }
4629 4630
   else if (streq (p[0], "route-noexec"))
... ...
@@ -4953,6 +4966,7 @@ add_option (struct options *options,
4953 4953
 	  msg (msglevel, "--auth-user-pass-verify requires a second parameter ('via-env' or 'via-file')");
4954 4954
 	  goto err;
4955 4955
 	}
4956
+      warn_multiple_script (options->auth_user_pass_verify_script, "auth-user-pass-verify");
4956 4957
       options->auth_user_pass_verify_script = p[1];
4957 4958
     }
4958 4959
   else if (streq (p[0], "client-connect") && p[1])
... ...
@@ -4960,6 +4974,7 @@ add_option (struct options *options,
4960 4960
       VERIFY_PERMISSION (OPT_P_SCRIPT);
4961 4961
       if (!no_more_than_n_args (msglevel, p, 2, NM_QUOTE_HINT))
4962 4962
 	goto err;
4963
+      warn_multiple_script (options->client_connect_script, "client-connect");
4963 4964
       options->client_connect_script = p[1];
4964 4965
     }
4965 4966
   else if (streq (p[0], "client-disconnect") && p[1])
... ...
@@ -4967,6 +4982,7 @@ add_option (struct options *options,
4967 4967
       VERIFY_PERMISSION (OPT_P_SCRIPT);
4968 4968
       if (!no_more_than_n_args (msglevel, p, 2, NM_QUOTE_HINT))
4969 4969
 	goto err;
4970
+      warn_multiple_script (options->client_disconnect_script, "client-disconnect");
4970 4971
       options->client_disconnect_script = p[1];
4971 4972
     }
4972 4973
   else if (streq (p[0], "learn-address") && p[1])
... ...
@@ -4974,6 +4990,7 @@ add_option (struct options *options,
4974 4974
       VERIFY_PERMISSION (OPT_P_SCRIPT);
4975 4975
       if (!no_more_than_n_args (msglevel, p, 2, NM_QUOTE_HINT))
4976 4976
 	goto err;
4977
+      warn_multiple_script (options->learn_address_script, "learn-address");
4977 4978
       options->learn_address_script = p[1];
4978 4979
     }
4979 4980
   else if (streq (p[0], "tmp-dir") && p[1])
... ...
@@ -5753,6 +5770,7 @@ add_option (struct options *options,
5753 5753
       VERIFY_PERMISSION (OPT_P_SCRIPT);
5754 5754
       if (!no_more_than_n_args (msglevel, p, 2, NM_QUOTE_HINT))
5755 5755
 	goto err;
5756
+      warn_multiple_script (options->tls_verify, "tls-verify");
5756 5757
       options->tls_verify = string_substitute (p[1], ',', ' ', &options->gc);
5757 5758
     }
5758 5759
   else if (streq (p[0], "tls-remote") && p[1])