[gnome-software] packagekit proxy: Fix http basic auth username/password URI building



commit 23f2ab1d546cd8881bbc0d40be2febc78283fdc9
Author: Kalev Lember <klember redhat com>
Date:   Wed Mar 28 11:41:53 2018 +0200

    packagekit proxy: Fix http basic auth username/password URI building
    
    We were constructing the URI the wrong way around and putting
    username/password after the hostname while it needs to be before it.
    Thanks to Jan-Michael Brummer for figuring this out!
    
    Fixes: https://gitlab.gnome.org/GNOME/gnome-software/issues/315

 plugins/packagekit/gs-plugin-packagekit-proxy.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
---
diff --git a/plugins/packagekit/gs-plugin-packagekit-proxy.c b/plugins/packagekit/gs-plugin-packagekit-proxy.c
index 27b2a8c7..aa724146 100644
--- a/plugins/packagekit/gs-plugin-packagekit-proxy.c
+++ b/plugins/packagekit/gs-plugin-packagekit-proxy.c
@@ -73,15 +73,17 @@ get_proxy_http (GsPlugin *plugin)
        }
 
        /* make PackageKit proxy string */
-       string = g_string_new (host);
+       string = g_string_new ("");
+       if (username != NULL || password != NULL) {
+               if (username != NULL)
+                       g_string_append_printf (string, "%s", username);
+               if (password != NULL)
+                       g_string_append_printf (string, ":%s", password);
+               g_string_append (string, "@");
+       }
+       g_string_append (string, host);
        if (port > 0)
                g_string_append_printf (string, ":%i", port);
-       if (username != NULL && password != NULL)
-               g_string_append_printf (string, "@%s:%s", username, password);
-       else if (username != NULL)
-               g_string_append_printf (string, "@%s", username);
-       else if (password != NULL)
-               g_string_append_printf (string, "@:%s", password);
        return g_string_free (string, FALSE);
 }
 


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