Re: [PATCH] yum requires the proxy settings to include a protocol (#484788, #567982).

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

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I did not test it out locally, but it looks fine reading through it, so, ack.

On Thu, 18 Mar 2010, Chris Lumens wrote:

Since yum requires the protocol and libcurl doesn't care if there's a protocol
given or not, add the protocol to the front of the proxy value itself.  Also,
both yum and libcurl will process the proxy setting if it's got a port on the
end so remove all the special port handling.
---
loader/loader.c     |   13 +---------
loader/loader.h     |    1 -
loader/urlinstall.c |    3 +-
loader/urls.c       |   58 +++++++++++++++++++++++++-------------------------
loader/urls.h       |    3 +-
yuminstall.py       |   23 +++++++++++++-------
6 files changed, 48 insertions(+), 53 deletions(-)

diff --git a/loader/loader.c b/loader/loader.c
index 1f60160..82c1a97 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -1092,8 +1092,7 @@ static void parseCmdLineFlags(struct loaderData_s * loaderData,
            loaderData->gdbServer = strdup(argv[i] + 4);
        else if (!strncasecmp(argv[i], "proxy=", 6))
            splitProxyParam(argv[i]+6, &loaderData->proxyUser,
-                            &loaderData->proxyPassword, &loaderData->proxy,
-                            &loaderData->proxyPort);
+                            &loaderData->proxyPassword, &loaderData->proxy);
        else if (numExtraArgs < (MAX_EXTRA_ARGS - 1)) {
            /* go through and append args we just want to pass on to */
            /* the anaconda script, but don't want to represent as a */
@@ -2311,17 +2310,9 @@ int main(int argc, char ** argv) {
        }

        if (loaderData.proxy && strcmp("", loaderData.proxy)) {
-            char *tmp = NULL;
            *argptr++ = "--proxy";

-            tmp = strdup(loaderData.proxy);
-            if (loaderData.proxyPort) {
-                tmp = realloc(tmp, strlen(tmp)+strlen(loaderData.proxyPort)+2);
-                tmp = strcat(tmp, ":");
-                tmp = strcat(tmp, loaderData.proxyPort);
-            }
-
-            *argptr++ = tmp;
+            *argptr++ = strdup(loaderData.proxy);

            if (loaderData.proxyUser) {
                int fd, ret;
diff --git a/loader/loader.h b/loader/loader.h
index a56d0b8..c88457f 100644
--- a/loader/loader.h
+++ b/loader/loader.h
@@ -163,7 +163,6 @@ struct loaderData_s {
     * settings off the command line, too.
     */
    char *proxy;
-    char *proxyPort;
    char *proxyUser;
    char *proxyPassword;
};
diff --git a/loader/urlinstall.c b/loader/urlinstall.c
index 85776de..54d1398 100644
--- a/loader/urlinstall.c
+++ b/loader/urlinstall.c
@@ -406,8 +406,7 @@ void setKickstartUrl(struct loaderData_s * loaderData, int argc,
    if (proxy) {
        splitProxyParam(proxy, &loaderData->proxyUser,
			       &loaderData->proxyPassword,
-			       &loaderData->proxy,
-			       &loaderData->proxyPort);
+			       &loaderData->proxy);
    }
    logMessage(INFO, "results of url ks, url %s", url);
}
diff --git a/loader/urls.c b/loader/urls.c
index a372a42..86151f5 100644
--- a/loader/urls.c
+++ b/loader/urls.c
@@ -63,8 +63,7 @@ int progress_cb(void *data, double dltotal, double dlnow, double ultotal, double
    return 0;
}

-int splitProxyParam(char *param, char **user, char **password, char **host,
-                    char **port) {
+int splitProxyParam(char *param, char **user, char **password, char **proxy) {
    /* proxy=[protocol://][username[:password]@]host[:port] */
    char *pattern = "([[:alpha:]]+://)?(([[:alnum:]]+)(:[^:@]+)?@)?([^:]+)(:[[:digit:]]+)?(/.*)?";
    regex_t re;
@@ -91,12 +90,28 @@ int splitProxyParam(char *param, char **user, char **password, char **host,
    if (pmatch[4].rm_so != -1)
        *password = strndup(param+pmatch[4].rm_so+1, pmatch[4].rm_eo-pmatch[4].rm_so-1);

-    if (pmatch[5].rm_so != -1)
-        *host = strndup(param+pmatch[5].rm_so, pmatch[5].rm_eo-pmatch[5].rm_so);
-
-    /* Skip the leading colon. */
-    if (pmatch[6].rm_so != -1)
-        *port = strndup(param+pmatch[6].rm_so+1, pmatch[6].rm_eo-pmatch[6].rm_so-1);
+    if (pmatch[5].rm_so != -1) {
+        char *portStr = NULL;
+
+        /* Skip the leading colon. */
+        if (pmatch[6].rm_so != -1)
+            portStr = strndup(param+pmatch[6].rm_so+1, pmatch[6].rm_eo-pmatch[6].rm_so-1);
+
+        /* If no parameter was given, default to HTTP.  yum will want to know
+         * the protocol, and curl will just ignore it if given.
+         */
+        if (pmatch[1].rm_so != -1) {
+            checked_asprintf(user, "%*s%*s%s", pmatch[1].rm_eo-pmatch[1].rm_so,
+                                               param+pmatch[1].rm_so,
+                                               pmatch[5].rm_eo-pmatch[5].rm_so,
+                                               param+pmatch[5].rm_so,
+                                               portStr);
+        } else {
+            checked_asprintf(user, "http://%*s%s";, pmatch[5].rm_eo-pmatch[5].rm_so,
+                                                   param+pmatch[5].rm_so,
+                                                   portStr);
+        }
+    }

    regfree(&re);
    return 1;
@@ -131,10 +146,6 @@ int urlinstTransfer(struct loaderData_s *loaderData, struct iurlinfo *ui,
    if (loaderData->proxy && strcmp(loaderData->proxy, "")) {
        curl_easy_setopt(curl, CURLOPT_PROXY, loaderData->proxy);

-        if (loaderData->proxyPort && strcmp(loaderData->proxyPort, ""))
-            curl_easy_setopt(curl, CURLOPT_PROXYPORT,
-                             strtol(loaderData->proxyPort, NULL, 10));
-
        if (loaderData->proxyUser && strcmp(loaderData->proxyUser, ""))
            curl_easy_setopt(curl, CURLOPT_PROXYUSERNAME,
                             loaderData->proxyUser);
@@ -224,10 +235,10 @@ static void setProxySensitivity(newtComponent co, void *dptr) {

int urlMainSetupPanel(struct loaderData_s *loaderData, struct iurlinfo * ui) {
    newtComponent form, okay, cancel, urlEntry, proxyCheckbox;
-    newtComponent proxyEntries[4];
+    newtComponent proxyEntries[3];
    newtComponent answer, text;
    char enableProxy;
-    char *url = "", *proxy = "", *proxyPort = "", *proxyUser = "", *proxyPassword = "";
+    char *url = "", *proxy = "", *proxyUser = "", *proxyPassword = "";
    char * reflowedText = NULL;
    int width, height;
    newtGrid buttons, grid, proxyGrid;
@@ -240,9 +251,6 @@ int urlMainSetupPanel(struct loaderData_s *loaderData, struct iurlinfo * ui) {
    if (loaderData->proxy)
        proxy = loaderData->proxy;

-    if (loaderData->proxyPort)
-        proxyPort = loaderData->proxyPort;
-
    if (loaderData->proxyUser)
        proxyUser = loaderData->proxyUser;

@@ -275,9 +283,8 @@ int urlMainSetupPanel(struct loaderData_s *loaderData, struct iurlinfo * ui) {
    newtComponentAddCallback(proxyCheckbox, setProxySensitivity, &proxyEntries);

    proxyEntries[0] = newtEntry(-1, -1, proxy, 35, (const char **) &proxy, NEWT_FLAG_SCROLL);
-    proxyEntries[1] = newtEntry(-1, -1, proxyPort, 5, (const char **) &proxyPort, 0);
-    proxyEntries[2] = newtEntry(-1, -1, proxyUser, 15, (const char **) &proxyUser, NEWT_FLAG_SCROLL);
-    proxyEntries[3] = newtEntry(-1, -1, proxyPassword, 15, (const char **) &proxyPassword, NEWT_FLAG_SCROLL|NEWT_FLAG_PASSWORD);
+    proxyEntries[1] = newtEntry(-1, -1, proxyUser, 15, (const char **) &proxyUser, NEWT_FLAG_SCROLL);
+    proxyEntries[2] = newtEntry(-1, -1, proxyPassword, 15, (const char **) &proxyPassword, NEWT_FLAG_SCROLL|NEWT_FLAG_PASSWORD);

    /* Set the initial proxy grid sensitivity to match. */
    if (enableProxy == ' ')
@@ -289,20 +296,15 @@ int urlMainSetupPanel(struct loaderData_s *loaderData, struct iurlinfo * ui) {
                     0, 0, 0, 0, 0, NEWT_ANCHOR_LEFT);
    newtGridSetField(proxyGrid, 1, 0, NEWT_GRID_COMPONENT, proxyEntries[0],
                     0, 0, 0, 0, 0, NEWT_ANCHOR_LEFT);
-    newtGridSetField(proxyGrid, 0, 1, NEWT_GRID_COMPONENT,
-                     newtLabel(-1, -1, _("Port")),
-                     0, 0, 0, 0, 0, NEWT_ANCHOR_LEFT);
-    newtGridSetField(proxyGrid, 1, 1, NEWT_GRID_COMPONENT, proxyEntries[1],
-                     0, 0, 0, 0, 0, NEWT_ANCHOR_LEFT);
    newtGridSetField(proxyGrid, 0, 2, NEWT_GRID_COMPONENT,
                     newtLabel(-1, -1, _("Username")),
                     0, 0, 0, 1, 0, NEWT_ANCHOR_LEFT);
-    newtGridSetField(proxyGrid, 1, 2, NEWT_GRID_COMPONENT, proxyEntries[2],
+    newtGridSetField(proxyGrid, 1, 2, NEWT_GRID_COMPONENT, proxyEntries[1],
                     0, 0, 0, 1, 0, NEWT_ANCHOR_LEFT);
    newtGridSetField(proxyGrid, 0, 3, NEWT_GRID_COMPONENT,
                     newtLabel(-1, -1, _("Password")),
                     0, 0, 0, 1, 0, NEWT_ANCHOR_LEFT);
-    newtGridSetField(proxyGrid, 1, 3, NEWT_GRID_COMPONENT, proxyEntries[3],
+    newtGridSetField(proxyGrid, 1, 3, NEWT_GRID_COMPONENT, proxyEntries[2],
                     0, 0, 0, 1, 0, NEWT_ANCHOR_LEFT);

    grid = newtCreateGrid(1, 5);
@@ -341,12 +343,10 @@ int urlMainSetupPanel(struct loaderData_s *loaderData, struct iurlinfo * ui) {

            if (enableProxy == '*') {
               loaderData->proxy = strdup(proxy);
-               loaderData->proxyPort = strdup(proxyPort);
               loaderData->proxyUser = strdup(proxyUser);
               loaderData->proxyPassword = strdup(proxyPassword);
            } else {
               loaderData->proxy = "";
-               loaderData->proxyPort = "";
               loaderData->proxyUser = "";
               loaderData->proxyPassword = "";
            }
diff --git a/loader/urls.h b/loader/urls.h
index ec84dde..e28b926 100644
--- a/loader/urls.h
+++ b/loader/urls.h
@@ -27,8 +27,7 @@ struct iurlinfo {
    char * url;
};

-int splitProxyParam(char *param, char **user, char **password, char **host,
-                    char **port);
+int splitProxyParam(char *param, char **user, char **password, char **host);
int urlMainSetupPanel(struct loaderData_s *loaderData, struct iurlinfo * ui);
int urlinstTransfer(struct loaderData_s *loaderData, struct iurlinfo *ui,
                    char **extraHeaders, char *dest);
diff --git a/yuminstall.py b/yuminstall.py
index 995c4a9..81ee71b 100644
--- a/yuminstall.py
+++ b/yuminstall.py
@@ -740,21 +740,28 @@ class AnacondaYum(YumSorter):
                if ksrepo.proxy:
                    m = pattern.match(ksrepo.proxy)

-                    if m and m.group(3):
+                    if m and m.group(5):
                        # If both a host and port was found, just paste them
                        # together using the colon at the beginning of the port
                        # match as a separator.  Otherwise, just use the host.
-                        if m.group(4):
-                            repo.proxy = m.group(3) + m.group(4)
+                        if m.group(6):
+                            repo.proxy = m.group(5) + m.group(6)
                        else:
-                            repo.proxy = m.group(3)
+                            repo.proxy = m.group(5)

-                    if m and m.group(5):
-                        repo.proxy_username = m.group(5)
+                        # yum also requires a protocol.  If none was given,
+                        # default to http.
+                        if m.group(1):
+                            repo.proxy = m.group(1) + repo.proxy
+                        else:
+                            repo.proxy = "http://"; + repo.proxy
+
+                    if m and m.group(3):
+                        repo.proxy_username = m.group(3)

-                    if m and m.group(6):
+                    if m and m.group(4):
                        # Skip the leading colon.
-                        repo.proxy_password = m.group(6)[1:]
+                        repo.proxy_password = m.group(4)[1:]

                repo.enable()
                extraRepos.append(repo)


- -- David Cantrell <dcantrell@xxxxxxxxxx>
Red Hat / Honolulu, HI

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAkuilqsACgkQ5hsjjIy1VknEUwCfVuYq+Vx5hMD5yh5PNy1wQMu3
DgsAmwXeMYHPVZxrJ8vKt5aYnkLM2AnP
=r6NX
-----END PGP SIGNATURE-----

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux