[NetworkManager-fortisslvpn/lr/export-import: 2/5] shared: add new config file writer



commit 0b6f1b6734d34a0bcd8f9576d8b31a39277e9d9c
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Wed Mar 20 22:24:58 2019 +0100

    shared: add new config file writer
    
    Should be useful for the service as well as export.

 shared/nm-fortissl-properties.c | 75 +++++++++++++++++++++++++++++++++++++++++
 shared/nm-fortissl-properties.h | 10 ++++--
 2 files changed, 83 insertions(+), 2 deletions(-)
---
diff --git a/shared/nm-fortissl-properties.c b/shared/nm-fortissl-properties.c
index f9713c3..0aa0591 100644
--- a/shared/nm-fortissl-properties.c
+++ b/shared/nm-fortissl-properties.c
@@ -235,3 +235,78 @@ nm_fortisslvpn_properties_validate_secrets (NMSettingVpn *s_vpn, GError **error)
 
        return *error ? FALSE : TRUE;
 }
+
+gboolean
+nm_fortisslvpn_write_config (GOutputStream *stream,
+                             NMSettingVpn *s_vpn,
+                             GError **error)
+{
+       const char *value;
+       gs_strfreev char **words = NULL;
+
+       if (!nm_fortisslvpn_properties_validate (s_vpn, error))
+               return FALSE;
+
+       value = nm_setting_vpn_get_data_item (s_vpn, NM_FORTISSLVPN_KEY_GATEWAY);
+       g_return_val_if_fail (value, FALSE);
+       words = g_strsplit (value, ":", 2);
+       if (!g_output_stream_printf (stream, NULL, NULL, error, "host = %s\n", words[0]))
+               return FALSE;
+       if (words[1]) {
+               if (!g_output_stream_printf (stream, NULL, NULL, error, "port = %s\n", words[1]))
+                       return FALSE;
+       }
+
+       /* Username; try SSLVPN specific username first, then generic username */
+       value = nm_setting_vpn_get_data_item (s_vpn, NM_FORTISSLVPN_KEY_USER);
+       if (!value || !*value)
+               value = nm_setting_vpn_get_user_name (s_vpn);
+       if (value) {
+               if (!g_output_stream_printf (stream, NULL, NULL, error, "username = %s\n", value))
+                       return FALSE;
+       }
+
+       value = nm_setting_vpn_get_secret (s_vpn, NM_FORTISSLVPN_KEY_PASSWORD);
+       if (value) {
+               if (!g_output_stream_printf (stream, NULL, NULL, error, "password = %s\n", value))
+                       return FALSE;
+       }
+
+       value = nm_setting_vpn_get_secret (s_vpn, NM_FORTISSLVPN_KEY_OTP);
+       if (value) {
+               if (!g_output_stream_printf (stream, NULL, NULL, error, "otp = %s\n", value))
+                       return FALSE;
+       }
+
+       value = nm_setting_vpn_get_data_item (s_vpn, NM_FORTISSLVPN_KEY_CA);
+       if (value) {
+               if (!g_output_stream_printf (stream, NULL, NULL, error, "ca-file = %s\n", value))
+                       return FALSE;
+       }
+
+       value = nm_setting_vpn_get_data_item (s_vpn, NM_FORTISSLVPN_KEY_CERT);
+       if (value) {
+               if (!g_output_stream_printf (stream, NULL, NULL, error, "user-cert = %s\n", value))
+                       return FALSE;
+       }
+
+       value = nm_setting_vpn_get_data_item (s_vpn, NM_FORTISSLVPN_KEY_KEY);
+       if (value) {
+               if (!g_output_stream_printf (stream, NULL, NULL, error, "user-key = %s\n", value))
+                       return FALSE;
+       }
+
+       value = nm_setting_vpn_get_data_item (s_vpn, NM_FORTISSLVPN_KEY_TRUSTED_CERT);
+       if (value) {
+               if (!g_output_stream_printf (stream, NULL, NULL, error, "trusted-cert = %s\n", value))
+                       return FALSE;
+       }
+
+       value = nm_setting_vpn_get_data_item (s_vpn, NM_FORTISSLVPN_KEY_REALM);
+       if (value) {
+               if (!g_output_stream_printf (stream, NULL, NULL, error, "realm = %s\n", value))
+                       return FALSE;
+       }
+
+       return TRUE;
+}
diff --git a/shared/nm-fortissl-properties.h b/shared/nm-fortissl-properties.h
index 8c24d3d..ce7b73d 100644
--- a/shared/nm-fortissl-properties.h
+++ b/shared/nm-fortissl-properties.h
@@ -25,8 +25,14 @@
 
 #include "nm-default.h"
 
-gboolean nm_fortisslvpn_properties_validate (NMSettingVpn *s_vpn, GError **error);
+gboolean nm_fortisslvpn_properties_validate (NMSettingVpn *s_vpn,
+                                             GError **error);
 
-gboolean nm_fortisslvpn_properties_validate_secrets (NMSettingVpn *s_vpn, GError **error);
+gboolean nm_fortisslvpn_properties_validate_secrets (NMSettingVpn *s_vpn,
+                                                     GError **error);
+
+gboolean nm_fortisslvpn_write_config (GOutputStream *stream,
+                                      NMSettingVpn *s_vpn,
+                                      GError **error);
 
 #endif /* __NM_FORTISSLVPN_PROPERTIES_H__ */


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