[network-manager-openvpn: 2/4] properties: skip comments from openvpn ciphers list



commit 214a996329435792b3bbc8d02933e52ce5e9b46f
Author: Beniamino Galvani <bgalvani redhat com>
Date:   Fri Dec 2 22:27:49 2016 +0100

    properties: skip comments from openvpn ciphers list
    
    We already skip the first comment block of the 'openvpn
    --show-ciphers' output before the first empty line.  However, there
    can be another comment block followed by other ciphers, for example:
    
      ~ $ openvpn --show-ciphers
      The following ciphers and cipher modes are available
      for use with OpenVPN.  Each cipher shown below may be
      used as a parameter to the --cipher option.  The default
      key size is shown as well as whether or not it can be
      changed with the --keysize directive.  Using a CBC mode
      is recommended. In static key mode only CBC mode is allowed.
    
      AES-128-CBC  (128 bit key, 128 bit block)
      AES-128-CFB  (128 bit key, 128 bit block, TLS client/server mode only)
    
      The following ciphers have a block size of less than 128 bits,
      and are therefore deprecated.  Do not use unless you have to.
    
      BF-CBC  (128 bit key by default, 64 bit block)
      BF-CFB  (128 bit key by default, 64 bit block, TLS client/server mode only)
      ~ $
    
    Basically, each empty line toggles between comments and ciphers.
    Implement this.

 properties/auth-helpers.c |   20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/properties/auth-helpers.c b/properties/auth-helpers.c
index 31df8d5..e8a4562 100644
--- a/properties/auth-helpers.c
+++ b/properties/auth-helpers.c
@@ -1003,7 +1003,7 @@ populate_cipher_combo (GtkComboBox *box, const char *user_cipher)
        gboolean user_added = FALSE;
        char *argv[3];
        GError *error = NULL;
-       gboolean success, found_blank = FALSE;
+       gboolean success, ignore_lines = TRUE;
 
        openvpn_binary = nm_find_openvpn ();
        if (!openvpn_binary)
@@ -1042,15 +1042,21 @@ populate_cipher_combo (GtkComboBox *box, const char *user_cipher)
        g_free (tmp);
 
        for (item = items; *item; item++) {
-               char *space = strchr (*item, ' ');
+               char *space;
 
-               /* Don't add anything until after the first blank line */
-               if (!found_blank) {
-                       if (!strlen (*item))
-                               found_blank = TRUE;
+               /* Don't add anything until after the first blank line. Also,
+                * any blank line indicates the start of a comment, ended by
+                * another blank line.
+                */
+               if (!strlen (*item)) {
+                       ignore_lines = !ignore_lines;
                        continue;
                }
 
+               if (ignore_lines)
+                       continue;
+
+               space = strchr (*item, ' ');
                if (space)
                        *space = '\0';
 


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