[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.7 and 1.8

version 1.7, 1997/04/14 00:48:44 version 1.8, 1997/04/16 05:02:48
Line 1 
Line 1 
 /*      $OpenBSD$       */  /*      $OpenBSD$       */
 /*      $NetBSD: fetch.c,v 1.5 1997/04/05 03:27:36 lukem Exp $  */  /*      $NetBSD: fetch.c,v 1.6 1997/04/14 09:09:19 lukem Exp $  */
   
 /*-  /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.   * Copyright (c) 1997 The NetBSD Foundation, Inc.
Line 128 
Line 128 
                 else if (strncasecmp(proxy, FTP_URL, sizeof(FTP_URL) - 1) == 0)                  else if (strncasecmp(proxy, FTP_URL, sizeof(FTP_URL) - 1) == 0)
                         host = proxy + sizeof(FTP_URL) - 1;                          host = proxy + sizeof(FTP_URL) - 1;
                 else {                  else {
                         warnx("Malformed proxy url: %s", proxy);                          warnx("Malformed proxy URL: %s", proxy);
                         goto cleanup_url_get;                          goto cleanup_url_get;
                 }                  }
                 if (EMPTYSTRING(host))                  if (EMPTYSTRING(host))
Line 153 
Line 153 
   
         if (isdigit(host[0])) {          if (isdigit(host[0])) {
                 if (inet_aton(host, &sin.sin_addr) == 0) {                  if (inet_aton(host, &sin.sin_addr) == 0) {
                         warnx("invalid IP address: %s", host);                          warnx("Invalid IP address: %s", host);
                         goto cleanup_url_get;                          goto cleanup_url_get;
                 }                  }
         } else {          } else {
Line 174 
Line 174 
         if (! EMPTYSTRING(portnum)) {          if (! EMPTYSTRING(portnum)) {
                 port = atoi(portnum);                  port = atoi(portnum);
                 if (port < 1 || (port & 0xffff) != port) {                  if (port < 1 || (port & 0xffff) != port) {
                         warnx("invalid port: %s", portnum);                          warnx("Invalid port: %s", portnum);
                         goto cleanup_url_get;                          goto cleanup_url_get;
                 }                  }
                 port = htons(port);                  port = htons(port);
Line 327 
Line 327 
         return (0);          return (0);
   
 improper:  improper:
         warnx("improper response from %s", host);          warnx("Improper response from %s", host);
 cleanup_url_get:  cleanup_url_get:
         if (s != -1)          if (s != -1)
                 close(s);                  close(s);
Line 372 
Line 372 
         static char lasthost[MAXHOSTNAMELEN];          static char lasthost[MAXHOSTNAMELEN];
         char *xargv[5];          char *xargv[5];
         char *cp, *line, *host, *dir, *file, *portnum;          char *cp, *line, *host, *dir, *file, *portnum;
           char *user, *pass;
         char *ftpproxy, *httpproxy;          char *ftpproxy, *httpproxy;
         int rval, xargc, argpos;          int rval, xargc, argpos;
         int dirhasglob, filehasglob;          int dirhasglob, filehasglob;
Line 396 
Line 397 
         for (rval = 0; (rval == 0) && (argpos < argc); free(line), argpos++) {          for (rval = 0; (rval == 0) && (argpos < argc); free(line), argpos++) {
                 if (strchr(argv[argpos], ':') == NULL)                  if (strchr(argv[argpos], ':') == NULL)
                         break;                          break;
                 host = dir = file = portnum = NULL;                  host = dir = file = portnum = user = pass = NULL;
   
                 /*                  /*
                  * We muck with the string, so we make a copy.                   * We muck with the string, so we make a copy.
Line 427 
Line 428 
                                 continue;                                  continue;
                         }                          }
                         host += sizeof(FTP_URL) - 1;                          host += sizeof(FTP_URL) - 1;
                         cp = strchr(host, '/');                          dir = strchr(host, '/');
   
                         /* Look for a port number after the host name. */                          /* Look for [user:pass@]host[:port] */
                           user = host;
                           pass = strpbrk(user, ":@/");
                           if (pass == NULL || *pass == '/')
                                   goto parsed_url;
                           if (*pass == '@') {
                                   warnx("Bad ftp URL: %s", argv[argpos]);
                                   rval = argpos + 1;
                                   continue;
                           }
                           *pass++ = '\0';
                           cp = strpbrk(pass, ":@/");
                           if (cp == NULL || *cp == '/') {
                                   portnum = pass;
                                   user = pass = NULL;
                                   goto parsed_url;
                           }
                           if (*cp == ':') {
                                   warnx("Bad ftp URL: %s", argv[argpos]);
                                   rval = argpos + 1;
                                   continue;
                           }
                           *cp++ = '\0';
                           host = cp;
                         portnum = strchr(host, ':');                          portnum = strchr(host, ':');
                         if (portnum != NULL)                          if (portnum != NULL)
                                 *portnum++ = '\0';                                  *portnum++ = '\0';
                 } else                          /* classic style `host:file' */  parsed_url:
                         cp = strchr(host, ':');                  } else {                        /* classic style `host:file' */
                           dir = strchr(host, ':');
                   }
                 if (EMPTYSTRING(host)) {                  if (EMPTYSTRING(host)) {
                         rval = argpos + 1;                          rval = argpos + 1;
                         continue;                          continue;
Line 444 
Line 470 
                  * If cp is NULL, the file wasn't specified                   * If cp is NULL, the file wasn't specified
                  * (URL looked something like ftp://host)                   * (URL looked something like ftp://host)
                  */                   */
                 if (cp != NULL)                  if (dir != NULL)
                         *cp++ = '\0';                          *dir++ = '\0';
   
                 /*                  /*
                  * Extract the file and (if present) directory name.                   * Extract the file and (if present) directory name.
                  */                   */
                 dir = cp;  
                 if (! EMPTYSTRING(dir)) {                  if (! EMPTYSTRING(dir)) {
                         cp = strrchr(cp, '/');                          cp = strrchr(dir, '/');
                         if (cp != NULL) {                          if (cp != NULL) {
                                 *cp++ = '\0';                                  *cp++ = '\0';
                                 file = cp;                                  file = cp;
Line 462 
Line 487 
                         }                          }
                 }                  }
                 if (debug)                  if (debug)
                         printf("host '%s', dir '%s', file '%s'\n",                          printf("user %s:%s host %s port %s dir %s file %s\n",
                             host, dir, file);                              user, pass, host, portnum, dir, file);
   
                 /*                  /*
                  * Set up the connection if we don't have one.                   * Set up the connection if we don't have one.
                  */                   */
                 if (strcmp(host, lasthost) != 0) {                  if (strcmp(host, lasthost) != 0) {
                           int oautologin;
   
                         (void)strcpy(lasthost, host);                          (void)strcpy(lasthost, host);
                         if (connected)                          if (connected)
                                 disconnect(0, NULL);                                  disconnect(0, NULL);
Line 476 
Line 503 
                         xargv[1] = host;                          xargv[1] = host;
                         xargv[2] = NULL;                          xargv[2] = NULL;
                         xargc = 2;                          xargc = 2;
                         if (portnum != NULL) {                          if (! EMPTYSTRING(portnum)) {
                                 xargv[2] = portnum;                                  xargv[2] = portnum;
                                 xargv[3] = NULL;                                  xargv[3] = NULL;
                                 xargc = 3;                                  xargc = 3;
                         }                          }
                           oautologin = autologin;
                           if (user != NULL)
                                   autologin = 0;
                         setpeer(xargc, xargv);                          setpeer(xargc, xargv);
                         if (connected == 0) {                          autologin = oautologin;
                                 warnx("Can't connect to host `%s'", host);                          if ((connected == 0) ||
                               ((connected == 1) && !login(host, user, pass)) ) {
                                   warnx("Can't connect or login to host `%s'",
                                       host);
                                 rval = argpos + 1;                                  rval = argpos + 1;
                                 continue;                                  continue;
                         }                          }
Line 491 
Line 524 
                         /* Always use binary transfers. */                          /* Always use binary transfers. */
                         setbinary(0, NULL);                          setbinary(0, NULL);
                 }                  }
                 else    /* already have connection, cd back to '/' */                  /* cd back to '/' */
                 {                  xargv[0] = "cd";
                         xargv[0] = "cd";                  xargv[1] = "/";
                         xargv[1] = "/";                  xargv[2] = NULL;
                         xargv[2] = NULL;                  cd(2, xargv);
                         cd(2, xargv);                  if (! dirchange) {
                         if (! dirchange) {                          rval = argpos + 1;
                                 rval = argpos + 1;                          continue;
                                 continue;  
                         }  
                 }                  }
   
                 dirhasglob = filehasglob = 0;                  dirhasglob = filehasglob = 0;

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8