[BACK]Return to fetch.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ftp

Diff for /src/usr.bin/ftp/fetch.c between version 1.189 and 1.190

version 1.189, 2020/02/13 15:54:10 version 1.190, 2020/02/19 07:29:53
Line 316 
Line 316 
         struct addrinfo hints, *res0, *res;          struct addrinfo hints, *res0, *res;
         const char *savefile;          const char *savefile;
         char *proxyurl = NULL;          char *proxyurl = NULL;
         char *credentials = NULL;          char *credentials = NULL, *proxy_credentials = NULL;
         int fd = -1, out = -1;          int fd = -1, out = -1;
         volatile sig_t oldintr, oldinti;          volatile sig_t oldintr, oldinti;
         FILE *fin = NULL;          FILE *fin = NULL;
Line 399 
Line 399 
          * contain the path. Basic auth from RFC 2617, valid           * contain the path. Basic auth from RFC 2617, valid
          * characters for path are in RFC 3986 section 3.3.           * characters for path are in RFC 3986 section 3.3.
          */           */
         if (proxyenv == NULL && (ishttpurl || ishttpsurl)) {          if (ishttpurl || ishttpsurl) {
                 if ((p = strchr(host, '@')) != NULL) {                  if ((p = strchr(host, '@')) != NULL) {
                         *p = '\0';                          *p = '\0';
                         credentials = recode_credentials(host);                          credentials = recode_credentials(host);
Line 471 
Line 471 
                                 warnx("Malformed proxy URL: %s", proxyenv);                                  warnx("Malformed proxy URL: %s", proxyenv);
                                 goto cleanup_url_get;                                  goto cleanup_url_get;
                         }                          }
                         credentials = recode_credentials(host);                          proxy_credentials = recode_credentials(host);
                         *path = '@'; /* restore @ in proxyurl */                          *path = '@'; /* restore @ in proxyurl */
   
                         /*                          /*
Line 615 
Line 615 
   
 #ifndef NOSSL  #ifndef NOSSL
                 if (proxyenv && sslhost)                  if (proxyenv && sslhost)
                         proxy_connect(fd, sslhost, credentials);                          proxy_connect(fd, sslhost, proxy_credentials);
 #endif /* !NOSSL */  #endif /* !NOSSL */
                 break;                  break;
         }          }
Line 707 
Line 707 
                  * Host: directive must use the destination host address for                   * Host: directive must use the destination host address for
                  * the original URI (path).                   * the original URI (path).
                  */                   */
                   ftp_printf(fin, "GET %s HTTP/1.1\r\n"
                       "Connection: close\r\n"
                       "Host: %s\r\n%s%s\r\n",
                       epath, proxyhost, buf ? buf : "", httpuseragent);
                 if (credentials)                  if (credentials)
                         ftp_printf(fin, "GET %s HTTP/1.1\r\n"                          ftp_printf(fin, "Authorization: Basic %s\r\n",
                             "Connection: close\r\n"                              credentials);
                             "Proxy-Authorization: Basic %s\r\n"                  if (proxy_credentials)
                             "Host: %s\r\n%s%s\r\n\r\n",                          ftp_printf(fin, "Proxy-Authorization: Basic %s\r\n",
                             epath, credentials,                              proxy_credentials);
                             proxyhost, buf ? buf : "", httpuseragent);                  ftp_printf(fin, "\r\n");
                 else  
                         ftp_printf(fin, "GET %s HTTP/1.1\r\n"  
                             "Connection: close\r\n"  
                             "Host: %s\r\n%s%s\r\n\r\n",  
                             epath, proxyhost, buf ? buf : "", httpuseragent);  
         } else {          } else {
                 if (verbose)                  if (verbose)
                         fprintf(ttyout, "Requesting %s\n", origline);                          fprintf(ttyout, "Requesting %s\n", origline);
Line 1117 
Line 1116 
         free(proxyurl);          free(proxyurl);
         free(newline);          free(newline);
         free(credentials);          free(credentials);
           free(proxy_credentials);
         return (rval);          return (rval);
 }  }
   
Line 1698 
Line 1698 
 {  {
         int l;          int l;
         char buf[1024];          char buf[1024];
         char *connstr, *hosttail, *port;          char *connstr, *hosttail, *port, *crlf;
           ssize_t sz;
   
         if (*host == '[' && (hosttail = strrchr(host, ']')) != NULL &&          if (*host == '[' && (hosttail = strrchr(host, ']')) != NULL &&
                 (hosttail[1] == '\0' || hosttail[1] == ':')) {                  (hosttail[1] == '\0' || hosttail[1] == ':')) {
Line 1730 
Line 1731 
 #endif /* !SMALL */  #endif /* !SMALL */
         if (write(socket, connstr, l) != l)          if (write(socket, connstr, l) != l)
                 err(1, "Could not send connect string");                  err(1, "Could not send connect string");
         read(socket, &buf, sizeof(buf)); /* only proxy header XXX: error handling? */          sz = read(socket, &buf, sizeof(buf) - 1);
           if (sz < 0)
                   err(1, "Failed to receive response from proxy");
           /* XXX should not assume we could read entire response at once.  */
           buf[sz] = '\0';
           if ((strncmp(buf, "HTTP/1.0 ", 9) != 0 &&
               strncmp(buf, "HTTP/1.1 ", 9) != 0) ||
               (crlf = strstr(buf, "\r\n")) == NULL)
                   errx(1, "Could not parse received response from proxy");
           *crlf = '\0';
           if (strncmp(buf + 9, "200 ", 4) != 0)
                   errx(1, "CONNECT command on proxy failed: %s", buf + 9);
           *crlf = '\r';   /* revert CR */
           if ((crlf = strstr(buf, "\r\n\r\n")) == NULL)
                   errx(1, "Could not read the end of response from proxy");
   
         free(connstr);          free(connstr);
         return(200);          return(200);
 }  }

Legend:
Removed from v.1.189  
changed lines
  Added in v.1.190