From 2c42a7ccfb7ffbb688de6e4e232645bff7aac0ed Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Thu, 18 Mar 2010 13:23:30 -0400 Subject: yum requires the proxy settings to include a protocol (#576691). 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 | 15 +++---------- loader/loader.h | 1 - loader/urlinstall.c | 3 +-- loader/urls.c | 65 ++++++++++++++++++++++++++--------------------------- loader/urls.h | 3 +-- 5 files changed, 37 insertions(+), 50 deletions(-) (limited to 'loader') diff --git a/loader/loader.c b/loader/loader.c index bdfc5407c..a9514d16d 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -1108,8 +1108,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 */ @@ -2329,19 +2328,11 @@ 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) { + if (strcmp(loaderData.proxyUser, "")) { int fd, ret; fd = open("/tmp/proxy", O_CREAT|O_TRUNC|O_RDWR, 0600); diff --git a/loader/loader.h b/loader/loader.h index a56d0b83c..c88457f36 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 85776de46..54d1398d8 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 a372a4290..a0441fc22 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,27 @@ 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 = ""; + + if (pmatch[6].rm_so != -1) + portStr = strndup(param+pmatch[6].rm_so, pmatch[6].rm_eo-pmatch[6].rm_so); + + /* 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(proxy, "%.*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(proxy, "http://%.*s%s", pmatch[5].rm_eo-pmatch[5].rm_so, + param+pmatch[5].rm_so, + portStr); + } + } regfree(&re); return 1; @@ -131,10 +145,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); @@ -212,8 +222,8 @@ char * addrToIp(char * hostname) { static void setProxySensitivity(newtComponent co, void *dptr) { int i; - /* It's 4 because there are four entry boxes in the proxy grid. Lame. */ - for (i = 0; i < 4; i++) { + /* It's 3 because there are three entry boxes in the proxy grid. Lame. */ + for (i = 0; i < 3; i++) { newtEntrySetFlags(*((newtComponent *) dptr), NEWT_FLAG_DISABLED, NEWT_FLAGS_TOGGLE); dptr += sizeof(newtComponent); @@ -224,10 +234,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 +250,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,34 +282,28 @@ 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 == ' ') setProxySensitivity(proxyCheckbox, proxyEntries); - proxyGrid = newtCreateGrid(2, 4); + proxyGrid = newtCreateGrid(2, 3); newtGridSetField(proxyGrid, 0, 0, NEWT_GRID_COMPONENT, newtLabel(-1, -1, _("Proxy URL")), 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, 1, NEWT_GRID_COMPONENT, proxyEntries[1], 0, 0, 0, 1, 0, NEWT_ANCHOR_LEFT); - newtGridSetField(proxyGrid, 0, 3, NEWT_GRID_COMPONENT, + newtGridSetField(proxyGrid, 0, 2, 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, 2, NEWT_GRID_COMPONENT, proxyEntries[2], 0, 0, 0, 1, 0, NEWT_ANCHOR_LEFT); grid = newtCreateGrid(1, 5); @@ -341,12 +342,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 ec84dde72..4ca538fa7 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 **proxy); int urlMainSetupPanel(struct loaderData_s *loaderData, struct iurlinfo * ui); int urlinstTransfer(struct loaderData_s *loaderData, struct iurlinfo *ui, char **extraHeaders, char *dest); -- cgit