[network-manager-openvpn/bg/inline-cert-fixes-bgo760746: 1/2] import: ignore empty lines



commit b733c7cce7534a1bd875633132e0900ddd4baf8e
Author: Beniamino Galvani <bgalvani redhat com>
Date:   Mon Jan 18 12:06:41 2016 +0100

    import: ignore empty lines
    
    This allows to properly import inline certificates when empty lines
    are present between tags and certificate, as well as configuration
    files with CRLF line terminators.

 properties/nm-openvpn.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)
---
diff --git a/properties/nm-openvpn.c b/properties/nm-openvpn.c
index 7fe16d4..16f0a23 100644
--- a/properties/nm-openvpn.c
+++ b/properties/nm-openvpn.c
@@ -638,7 +638,9 @@ import (NMVpnEditorPlugin *iface, const char *path, GError **error)
        NMConnection *connection = NULL;
        char *contents = NULL;
        char **lines = NULL;
+       char **lines2 = NULL;
        char *ext;
+       int i, j;
 
        ext = strrchr (path, '.');
 
@@ -681,11 +683,25 @@ import (NMVpnEditorPlugin *iface, const char *path, GError **error)
                goto out;
        }
 
-       connection = do_import (path, lines, error);
+       /* Remove empty lines */
+       lines2 = g_new (char *, g_strv_length (lines) + 1);
+       for (i = 0, j = 0; lines[i]; i++) {
+               if (lines[i][0])
+                       lines2[j++] = lines[i];
+               else
+                       free (lines[i]);
+       }
+
+       lines2[j] = NULL;
+       g_clear_pointer (&lines, g_free);
+
+       connection = do_import (path, lines2, error);
 
 out:
        if (lines)
                g_strfreev (lines);
+       if (lines2)
+               g_strfreev (lines2);
        g_free (contents);
        return connection;
 }


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