[network-manager-openvpn/th/export-bgo764132: 11/23] properties: refactor do_export() (refactor writing "tls-auth")



commit 3c9ba7ae349169d4bd64b6b624014dfda7b2d1f8
Author: Thomas Haller <thaller redhat com>
Date:   Thu Mar 24 10:59:32 2016 +0100

    properties: refactor do_export() (refactor writing "tls-auth")

 properties/import-export.c |   25 +++++++++----------------
 1 files changed, 9 insertions(+), 16 deletions(-)
---
diff --git a/properties/import-export.c b/properties/import-export.c
index 31565df..357a72a 100644
--- a/properties/import-export.c
+++ b/properties/import-export.c
@@ -1648,8 +1648,6 @@ do_export_create (NMConnection *connection, const char *path, GError **error)
        gs_free char *private_key = NULL;
        const char *local_ip = NULL;
        const char *remote_ip = NULL;
-       gs_free char *tls_auth = NULL;
-       const char *tls_auth_dir = NULL;
        gs_free char *device = NULL;
        const char *device_type = NULL;
        const char *device_default = "tun";
@@ -1771,14 +1769,6 @@ do_export_create (NMConnection *connection, const char *path, GError **error)
        if (_arg_is_set (value))
                remote_ip = value;
 
-       value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_TA);
-       if (_arg_is_set (value))
-               tls_auth = nmv_utils_str_utf8safe_unescape (value);
-
-       value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_TA_DIR);
-       if (_arg_is_set (value))
-               tls_auth_dir = value;
-
        value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_REMOTE_RANDOM);
        if (value && !strcmp (value, "yes"))
                randomize_hosts = TRUE;
@@ -1905,17 +1895,20 @@ do_export_create (NMConnection *connection, const char *path, GError **error)
        if (local_ip && remote_ip)
                args_write_line (f, "ifconfig", local_ip, remote_ip);
 
-       if (   !strcmp(connection_type, NM_OPENVPN_CONTYPE_TLS)
-           || !strcmp(connection_type, NM_OPENVPN_CONTYPE_PASSWORD_TLS)) {
-
+       if (NM_IN_STRSET (connection_type,
+                         NM_OPENVPN_CONTYPE_TLS,
+                         NM_OPENVPN_CONTYPE_PASSWORD_TLS)) {
                args_write_line_setting_value (f, "tls-remote", s_vpn, NM_OPENVPN_KEY_TLS_REMOTE);
                args_write_line_setting_value (f, "remote-cert-tls", s_vpn, NM_OPENVPN_KEY_REMOTE_CERT_TLS);
 
-               if (tls_auth) {
+               value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_TA);
+               if (_arg_is_set (value)) {
+                       gs_free char *s_free = NULL;
+
                        args_write_line (f,
                                         "tls-auth",
-                                        tls_auth,
-                                        tls_auth_dir);
+                                        nmv_utils_str_utf8safe_unescape_c (value, &s_free),
+                                        _arg_is_set (nm_setting_vpn_get_data_item (s_vpn, 
NM_OPENVPN_KEY_TA_DIR)));
                }
        }
 


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