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
... ...
@@ -3478,6 +3478,15 @@ msglevel_forward_compatible (struct options *options, const int msglevel)
3478 3478
 }
3479 3479
 
3480 3480
 static void
3481
+warn_multiple_script (const char *script, const char *type) {
3482
+      if (script) {
3483
+	msg (M_WARN, "Multiple --%s scripts defined.  "
3484
+	     "The previously configured script is overridden.", type);
3485
+      }
3486
+}
3487
+
3488
+
3489
+static void
3481 3490
 add_option (struct options *options,
3482 3491
 	    char *p[],
3483 3492
 	    const char *file,
... ...
@@ -3877,6 +3886,7 @@ add_option (struct options *options,
3877 3877
       VERIFY_PERMISSION (OPT_P_SCRIPT);
3878 3878
       if (!no_more_than_n_args (msglevel, p, 2, NM_QUOTE_HINT))
3879 3879
 	goto err;
3880
+      warn_multiple_script (options->ipchange, "ipchange");
3880 3881
       options->ipchange = string_substitute (p[1], ',', ' ', &options->gc);
3881 3882
     }
3882 3883
   else if (streq (p[0], "float"))
... ...
@@ -3923,6 +3933,7 @@ add_option (struct options *options,
3923 3923
       VERIFY_PERMISSION (OPT_P_SCRIPT);
3924 3924
       if (!no_more_than_n_args (msglevel, p, 2, NM_QUOTE_HINT))
3925 3925
 	goto err;
3926
+      warn_multiple_script (options->up_script, "up");
3926 3927
       options->up_script = p[1];
3927 3928
     }
3928 3929
   else if (streq (p[0], "down") && p[1])
... ...
@@ -3930,6 +3941,7 @@ add_option (struct options *options,
3930 3930
       VERIFY_PERMISSION (OPT_P_SCRIPT);
3931 3931
       if (!no_more_than_n_args (msglevel, p, 2, NM_QUOTE_HINT))
3932 3932
 	goto err;
3933
+      warn_multiple_script (options->down_script, "down");
3933 3934
       options->down_script = p[1];
3934 3935
     }
3935 3936
   else if (streq (p[0], "down-pre"))
... ...
@@ -4598,6 +4610,7 @@ add_option (struct options *options,
4598 4598
       VERIFY_PERMISSION (OPT_P_SCRIPT);
4599 4599
       if (!no_more_than_n_args (msglevel, p, 2, NM_QUOTE_HINT))
4600 4600
 	goto err;
4601
+      warn_multiple_script (options->route_script, "route-up");
4601 4602
       options->route_script = p[1];
4602 4603
     }
4603 4604
   else if (streq (p[0], "route-noexec"))
... ...
@@ -4927,6 +4940,7 @@ add_option (struct options *options,
4927 4927
 	  msg (msglevel, "--auth-user-pass-verify requires a second parameter ('via-env' or 'via-file')");
4928 4928
 	  goto err;
4929 4929
 	}
4930
+      warn_multiple_script (options->auth_user_pass_verify_script, "auth-user-pass-verify");
4930 4931
       options->auth_user_pass_verify_script = p[1];
4931 4932
     }
4932 4933
   else if (streq (p[0], "client-connect") && p[1])
... ...
@@ -4934,6 +4948,7 @@ add_option (struct options *options,
4934 4934
       VERIFY_PERMISSION (OPT_P_SCRIPT);
4935 4935
       if (!no_more_than_n_args (msglevel, p, 2, NM_QUOTE_HINT))
4936 4936
 	goto err;
4937
+      warn_multiple_script (options->client_connect_script, "client-connect");
4937 4938
       options->client_connect_script = p[1];
4938 4939
     }
4939 4940
   else if (streq (p[0], "client-disconnect") && p[1])
... ...
@@ -4941,6 +4956,7 @@ add_option (struct options *options,
4941 4941
       VERIFY_PERMISSION (OPT_P_SCRIPT);
4942 4942
       if (!no_more_than_n_args (msglevel, p, 2, NM_QUOTE_HINT))
4943 4943
 	goto err;
4944
+      warn_multiple_script (options->client_disconnect_script, "client-disconnect");
4944 4945
       options->client_disconnect_script = p[1];
4945 4946
     }
4946 4947
   else if (streq (p[0], "learn-address") && p[1])
... ...
@@ -4948,6 +4964,7 @@ add_option (struct options *options,
4948 4948
       VERIFY_PERMISSION (OPT_P_SCRIPT);
4949 4949
       if (!no_more_than_n_args (msglevel, p, 2, NM_QUOTE_HINT))
4950 4950
 	goto err;
4951
+      warn_multiple_script (options->learn_address_script, "learn-address");
4951 4952
       options->learn_address_script = p[1];
4952 4953
     }
4953 4954
   else if (streq (p[0], "tmp-dir") && p[1])
... ...
@@ -5708,6 +5725,7 @@ add_option (struct options *options,
5708 5708
       VERIFY_PERMISSION (OPT_P_SCRIPT);
5709 5709
       if (!no_more_than_n_args (msglevel, p, 2, NM_QUOTE_HINT))
5710 5710
 	goto err;
5711
+      warn_multiple_script (options->tls_verify, "tls-verify");
5711 5712
       options->tls_verify = string_substitute (p[1], ',', ' ', &options->gc);
5712 5713
     }
5713 5714
   else if (streq (p[0], "tls-remote") && p[1])