[network-manager-openswan/dcbw/cleanups: 19/27] fixup! core: rework connect process and subprocess handling



commit b0cb4fa01c3e4162338bac6f83c18980695d7c1b
Author: Dan Williams <dcbw redhat com>
Date:   Thu Oct 2 13:31:49 2014 -0500

    fixup! core: rework connect process and subprocess handling

 src/nm-openswan-service.c |   25 ++++++++++---------------
 1 files changed, 10 insertions(+), 15 deletions(-)
---
diff --git a/src/nm-openswan-service.c b/src/nm-openswan-service.c
index 343a0e3..529e012 100644
--- a/src/nm-openswan-service.c
+++ b/src/nm-openswan-service.c
@@ -716,7 +716,7 @@ io_cb (GIOChannel *source, GIOCondition condition, gpointer user_data)
        GIOStatus status;
        gsize bytes_read = 0;
        gboolean ret = G_SOURCE_CONTINUE;
-       guint blank;
+       const char *found;
 
        if (condition & (G_IO_ERR | G_IO_HUP)) {
                g_warning ("PTY spawn: pipe error!");
@@ -734,28 +734,19 @@ io_cb (GIOChannel *source, GIOCondition condition, gpointer user_data)
                return G_SOURCE_CONTINUE;
 
        g_string_append (priv->io_buf, buf);
-       DEBUG ("VPN request '%s'", priv->io_buf->str);
        if (priv->io_buf->len < strlen (PASSPHRASE_REQUEST))
                return G_SOURCE_CONTINUE;
 
-       if (priv->io_buf->len > 1024) {
-               ret = G_SOURCE_REMOVE;
-               goto done;
-       }
-
-       /* Strip leading whitespace */
-       blank = 0;
-       while (g_ascii_isspace (priv->io_buf->str[blank]))
-               blank++;
-       if (blank)
-               g_string_erase (priv->io_buf, 0, blank);
+       DEBUG ("VPN request '%s'", priv->io_buf->str);
 
-       if (strcmp (priv->io_buf->str, PASSPHRASE_REQUEST) == 0) {
+       found = strstr (priv->io_buf->str, PASSPHRASE_REQUEST);
+       if (found) {
                GError *error = NULL;
                gsize bytes_written;
                const char *password = priv->password;
 
-               g_string_erase (priv->io_buf, 0, strlen (PASSPHRASE_REQUEST));
+               /* Erase everything up to and including the passphrase request */
+               g_string_erase (priv->io_buf, 0, (found + strlen (PASSPHRASE_REQUEST)) - priv->io_buf->str);
 
                if (!password) {
                        /* FIXME: request new password interactively */
@@ -781,6 +772,10 @@ io_cb (GIOChannel *source, GIOCondition condition, gpointer user_data)
                DEBUG ("PTY: password written");
        }
 
+       /* Truncate large buffer if we haven't gotten the password request yet */
+       if (priv->io_buf->len > sizeof (buf) * 4)
+               g_string_erase (priv->io_buf, 0, sizeof (buf) * 3);
+
 done:
        if (ret == G_SOURCE_REMOVE) {
                priv->io_id = 0;


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