[network-manager-openvpn/dcbw/openvpn-restart: 2/5] core: fix protocol and port specified with remote address



commit 7a0b3e7b59697a38fede19c6d6d05531d5001fb6
Author: Dan Williams <dcbw redhat com>
Date:   Fri Oct 10 09:31:43 2014 -0500

    core: fix protocol and port specified with remote address
    
    If the port and protocol were specified in the remote address
    option (eg, "host [port] [proto]") nm-openvpn-service still
    added explicit --proto and --port options later, which confused
    openvpn.
    
    Let the port/proto of the 'remote' take precedence, and fallback
    to using the separately configured port or protocol options if
    the 'remote' didn't specify any.

 src/nm-openvpn-service.c |   53 +++++++++++++++++++++------------------------
 1 files changed, 25 insertions(+), 28 deletions(-)
---
diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c
index 7793b07..1404111 100644
--- a/src/nm-openvpn-service.c
+++ b/src/nm-openvpn-service.c
@@ -868,6 +868,7 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
        GPid pid;
        gboolean dev_type_is_tap;
        char *stmp;
+       const char *defport, *proto_tcp;
 
        /* Find openvpn */
        openvpn_binary = nm_find_openvpn ();
@@ -905,6 +906,14 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
        args = g_ptr_array_new ();
        add_openvpn_arg (args, openvpn_binary);
 
+       defport = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PORT);
+       if (defport && !defport[0])
+               defport = NULL;
+
+       proto_tcp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP);
+       if (proto_tcp && !proto_tcp[0])
+               proto_tcp = NULL;
+
        tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_REMOTE);
        if (tmp && *tmp) {
                char *tok, *port, *proto;
@@ -930,8 +939,19 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
                                                g_free (tmp_dup);
                                                return FALSE;
                                        }
+                               } else if (defport) {
+                                       if (!add_openvpn_arg_int (args, defport)) {
+                                               g_set_error (error,
+                                                            NM_VPN_PLUGIN_ERROR,
+                                                            NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
+                                                            _("Invalid port number '%s'."),
+                                                            defport);
+                                               free_openvpn_args (args);
+                                               return FALSE;
+                                       }
                                } else
-                                       add_openvpn_arg (args, "1194"); /* use default IANA port */
+                                       add_openvpn_arg (args, "1194"); /* default IANA port */
+
                                if (proto) {
                                        if (!strcmp (proto, "udp") || !strcmp (proto, "tcp"))
                                                add_openvpn_arg (args, proto);
@@ -944,7 +964,10 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
                                                g_free (tmp_dup);
                                                return FALSE;
                                        }
-                               }
+                               } else if (proto_tcp && !strcmp (proto_tcp, "yes"))
+                                       add_openvpn_arg (args, "tcp");
+                               else
+                                       add_openvpn_arg (args, "udp");
                        }
                }
                g_free (tmp_dup);
@@ -1015,32 +1038,6 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
                dev_type_is_tap = (g_strcmp0 (tmp2, "tap") == 0);
        }
 
-       /* Protocol, either tcp or udp */
-       add_openvpn_arg (args, "--proto");
-       tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP);
-       if (tmp && !strcmp (tmp, "yes"))
-               add_openvpn_arg (args, "tcp-client");
-       else
-               add_openvpn_arg (args, "udp");
-
-       /* Port */
-       add_openvpn_arg (args, "--port");
-       tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PORT);
-       if (tmp && strlen (tmp)) {
-               if (!add_openvpn_arg_int (args, tmp)) {
-                       g_set_error (error,
-                                    NM_VPN_PLUGIN_ERROR,
-                                    NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
-                                    _("Invalid port number '%s'."),
-                                    tmp);
-                       free_openvpn_args (args);
-                       return FALSE;
-               }
-       } else {
-               /* Default to IANA assigned port 1194 */
-               add_openvpn_arg (args, "1194");
-       }
-
        /* Cipher */
        tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CIPHER);
        if (tmp && strlen (tmp)) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]