[network-manager-openvpn/th/chroot-rh1377708: 2/7] service: cleanup call to nm_openvpn_start_openvpn_binary()



commit 00e5fcad2b66cdf141e72b3076932b850d384c9f
Author: Thomas Haller <thaller redhat com>
Date:   Tue Sep 20 16:10:35 2016 +0200

    service: cleanup call to nm_openvpn_start_openvpn_binary()
    
    We possibly need the entire NMConnection in nm_openvpn_start_openvpn_binary().
    Merge nm_openvpn_start_openvpn_binary() with _connect_common().

 src/nm-openvpn-service.c |   98 +++++++++++++++++++--------------------------
 1 files changed, 41 insertions(+), 57 deletions(-)
---
diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c
index f7afd3b..c08d772 100644
--- a/src/nm-openvpn-service.c
+++ b/src/nm-openvpn-service.c
@@ -1095,13 +1095,11 @@ check_chroot_dir_usability (const char *chdir, const char *user)
 
 static gboolean
 nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
-                                 NMSettingVpn *s_vpn,
-                                 const char *default_username,
-                                 const char *uuid,
+                                 NMConnection *connection,
                                  GError **error)
 {
        NMOpenvpnPluginPrivate *priv = NM_OPENVPN_PLUGIN_GET_PRIVATE (plugin);
-       const char *openvpn_binary, *auth, *connection_type, *tmp, *tmp2, *tmp3, *tmp4;
+       const char *openvpn_binary, *auth, *tmp, *tmp2, *tmp3, *tmp4;
        GPtrArray *args;
        GPid pid;
        gboolean dev_type_is_tap;
@@ -1109,6 +1107,34 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
        const char *defport, *proto_tcp;
        const char *nm_openvpn_user, *nm_openvpn_group, *nm_openvpn_chroot;
        gs_free char *bus_name = NULL;
+       NMSettingVpn *s_vpn;
+       const char *connection_type;
+
+       s_vpn = nm_connection_get_setting_vpn (connection);
+       if (!s_vpn) {
+               g_set_error_literal (error,
+                                    NM_VPN_PLUGIN_ERROR,
+                                    NM_VPN_PLUGIN_ERROR_INVALID_CONNECTION,
+                                    _("Could not process the request because the VPN connection settings 
were invalid."));
+               return FALSE;
+       }
+
+       connection_type = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CONNECTION_TYPE);
+       if (!validate_connection_type (connection_type)) {
+               g_set_error_literal (error,
+                                    NM_VPN_PLUGIN_ERROR,
+                                    NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
+                                    _("Invalid connection type."));
+               return FALSE;
+       }
+
+       /* Validate the properties */
+       if (!nm_openvpn_properties_validate (s_vpn, error))
+               return FALSE;
+
+       /* Validate secrets */
+       if (!nm_openvpn_secrets_validate (s_vpn, error))
+               return FALSE;
 
        /* Find openvpn */
        openvpn_binary = nm_find_openvpn ();
@@ -1131,15 +1157,6 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
                }
        }
 
-       connection_type = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CONNECTION_TYPE);
-       if (!validate_connection_type (connection_type)) {
-               g_set_error_literal (error,
-                                    NM_VPN_PLUGIN_ERROR,
-                                    NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
-                                    _("Invalid connection type."));
-               return FALSE;
-       }
-
        args = g_ptr_array_new ();
        add_openvpn_arg (args, openvpn_binary);
 
@@ -1569,7 +1586,8 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
        /* Management socket for localhost access to supply username and password */
        add_openvpn_arg (args, "--management");
        g_warn_if_fail (priv->mgt_path == NULL);
-       priv->mgt_path = g_strdup_printf (LOCALSTATEDIR "/run/NetworkManager/nm-openvpn-%s", uuid);
+       priv->mgt_path = g_strdup_printf (LOCALSTATEDIR "/run/NetworkManager/nm-openvpn-%s",
+                                         nm_connection_get_uuid (connection));
        add_openvpn_arg (args, priv->mgt_path);
        add_openvpn_arg (args, "unix");
        add_openvpn_arg (args, "--management-client-user");
@@ -1730,7 +1748,8 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
            || nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_HTTP_PROXY_USERNAME)) {
 
                priv->io_data = g_malloc0 (sizeof (NMOpenvpnPluginIOData));
-               update_io_data_from_vpn_setting (priv->io_data, s_vpn, default_username);
+               update_io_data_from_vpn_setting (priv->io_data, s_vpn,
+                                                nm_setting_vpn_get_user_name (s_vpn));
                nm_openvpn_schedule_connect_timer (plugin);
        }
 
@@ -1817,51 +1836,16 @@ _connect_common (NMVpnServicePlugin   *plugin,
                  GVariant      *details,
                  GError       **error)
 {
-       NMSettingVpn *s_vpn;
-       const char *connection_type;
-       const char *user_name;
-
-       if (!real_disconnect (plugin, error)) {
-               _LOGW ("Could not clean up previous daemon run: %s", (*error)->message);
-               g_clear_error (error);
-       }
-
-       s_vpn = nm_connection_get_setting_vpn (connection);
-       if (!s_vpn) {
-               g_set_error_literal (error,
-                                    NM_VPN_PLUGIN_ERROR,
-                                    NM_VPN_PLUGIN_ERROR_INVALID_CONNECTION,
-                                    _("Could not process the request because the VPN connection settings 
were invalid."));
-               return FALSE;
-       }
+       GError *local = NULL;
 
-       connection_type = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_CONNECTION_TYPE);
-       if (!validate_connection_type (connection_type)) {
-               g_set_error_literal (error,
-                                    NM_VPN_PLUGIN_ERROR,
-                                    NM_VPN_PLUGIN_ERROR_INVALID_CONNECTION,
-                                    _("Could not process the request because the openvpn connection type was 
invalid."));
-               return FALSE;
+       if (!real_disconnect (plugin, &local)) {
+               _LOGW ("Could not clean up previous daemon run: %s", local->message);
+               g_error_free (local);
        }
 
-       /* Validate the properties */
-       if (!nm_openvpn_properties_validate (s_vpn, error))
-               return FALSE;
-
-       /* Validate secrets */
-       if (!nm_openvpn_secrets_validate (s_vpn, error))
-               return FALSE;
-
-       /* Finally try to start OpenVPN */
-       user_name = nm_setting_vpn_get_user_name (s_vpn);
-       if (!nm_openvpn_start_openvpn_binary (NM_OPENVPN_PLUGIN (plugin),
-                                             s_vpn,
-                                             user_name,
-                                             nm_connection_get_uuid (connection),
-                                             error))
-               return FALSE;
-
-       return TRUE;
+       return nm_openvpn_start_openvpn_binary (NM_OPENVPN_PLUGIN (plugin),
+                                               connection,
+                                               error);
 }
 
 static gboolean


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