[network-manager-openswan/dcbw/libreswan: 11/16] core: work around libreswan config-terminating oddity



commit 60a504ac18004fcc41649f833e63b1f658deef3e
Author: Dan Williams <dcbw redhat com>
Date:   Mon Oct 20 16:35:37 2014 -0500

    core: work around libreswan config-terminating oddity
    
    libreswan doesn't want a \n on the last line of configuration,
    but openswan segfaults if you don't have it.  Yay.

 src/nm-openswan-service.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/src/nm-openswan-service.c b/src/nm-openswan-service.c
index ad6227c..294b4d3 100644
--- a/src/nm-openswan-service.c
+++ b/src/nm-openswan-service.c
@@ -568,7 +568,10 @@ write_config_option (int fd, const char *format, ...)
 }
 
 static void
-nm_openswan_config_write (gint fd, NMConnection *connection, GError **error)
+nm_openswan_config_write (gint fd,
+                          NMConnection *connection,
+                          gboolean libreswan,
+                          GError **error)
 {
        NMSettingVPN *s_vpn = nm_connection_get_setting_vpn (connection);
        const char *con_name = nm_connection_get_uuid (connection);
@@ -619,7 +622,16 @@ nm_openswan_config_write (gint fd, NMConnection *connection, GError **error)
        write_config_option (fd, " salifetime=24h\n");
        write_config_option (fd, " ikelifetime=24h\n");
        write_config_option (fd, " keyingtries=1\n");
-       write_config_option (fd, " auto=add\n");
+       write_config_option (fd, " auto=add");
+
+       /* openswan requires a terminating \n (otherwise it segfaults) while
+        * libreswan fails parsing the configuration if you include the \n.
+        * WTF?
+        */
+       if (!libreswan)
+               (void) write (fd, "\n", 1);
+       if (debug)
+               g_print ("\n");
 }
 
 static gboolean
@@ -989,7 +1001,7 @@ connect_step (NMOpenSwanPlugin *self, GError **error)
                               "auto", "--replace", "--config", "-", uuid, NULL))
                        return FALSE;
                priv->watch_id = g_child_watch_add (priv->pid, child_watch_cb, self);
-               nm_openswan_config_write (fd, priv->connection, error);
+               nm_openswan_config_write (fd, priv->connection, priv->libreswan, error);
                close (fd);
                return TRUE;
 


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