[BACK]Return to util.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / usr.bin / ftp

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/usr.bin/ftp/util.c between version 1.148 and 1.149

version 1.148, 2008/08/13 04:59:13 version 1.149, 2009/04/12 07:07:41
Line 163  setpeer(int argc, char *argv[])
Line 163  setpeer(int argc, char *argv[])
 }  }
   
 static void  static void
 parse_feat(const char *line)  parse_feat(const char *fline)
 {  {
   
                         /*                          /*
                          * work-around broken ProFTPd servers that can't                           * work-around broken ProFTPd servers that can't
                          * even obey RFC2389.                           * even obey RFC2389.
                          */                           */
         while (*line && isspace((int)*line))          while (*fline && isspace((int)*fline))
                 line++;                  fline++;
   
         if (strcasecmp(line, "MDTM") == 0)          if (strcasecmp(fline, "MDTM") == 0)
                 features[FEAT_MDTM] = 1;                  features[FEAT_MDTM] = 1;
         else if (strncasecmp(line, "MLST", sizeof("MLST") - 1) == 0) {          else if (strncasecmp(fline, "MLST", sizeof("MLST") - 1) == 0) {
                 features[FEAT_MLST] = 1;                  features[FEAT_MLST] = 1;
         } else if (strcasecmp(line, "REST STREAM") == 0)          } else if (strcasecmp(fline, "REST STREAM") == 0)
                 features[FEAT_REST_STREAM] = 1;                  features[FEAT_REST_STREAM] = 1;
         else if (strcasecmp(line, "SIZE") == 0)          else if (strcasecmp(fline, "SIZE") == 0)
                 features[FEAT_SIZE] = 1;                  features[FEAT_SIZE] = 1;
         else if (strcasecmp(line, "TVFS") == 0)          else if (strcasecmp(fline, "TVFS") == 0)
                 features[FEAT_TVFS] = 1;                  features[FEAT_TVFS] = 1;
 }  }
   
Line 372  int
Line 372  int
 ftp_login(const char *host, const char *luser, const char *lpass)  ftp_login(const char *host, const char *luser, const char *lpass)
 {  {
         char tmp[80];          char tmp[80];
         char *user, *pass, *acct, *p;          char *fuser, *pass, *facct, *p;
         char emptypass[] = "";          char emptypass[] = "";
         const char *errormsg;          const char *errormsg;
         int n, aflag, rval, nlen;          int n, aflag, rval, nlen;
   
         aflag = rval = 0;          aflag = rval = 0;
         user = pass = acct = NULL;          fuser = pass = facct = NULL;
         if (luser)          if (luser)
                 user = ftp_strdup(luser);                  fuser = ftp_strdup(luser);
         if (lpass)          if (lpass)
                 pass = ftp_strdup(lpass);                  pass = ftp_strdup(lpass);
   
         DPRINTF("ftp_login: user `%s' pass `%s' host `%s'\n",          DPRINTF("ftp_login: user `%s' pass `%s' host `%s'\n",
             STRorNULL(user), STRorNULL(pass), STRorNULL(host));              STRorNULL(fuser), STRorNULL(pass), STRorNULL(host));
   
         /*          /*
          * Set up arguments for an anonymous FTP session, if necessary.           * Set up arguments for an anonymous FTP session, if necessary.
          */           */
         if (anonftp) {          if (anonftp) {
                 FREEPTR(user);                  FREEPTR(fuser);
                 user = ftp_strdup("anonymous"); /* as per RFC1635 */                  fuser = ftp_strdup("anonymous");        /* as per RFC1635 */
                 FREEPTR(pass);                  FREEPTR(pass);
                 pass = ftp_strdup(getoptionvalue("anonpass"));                  pass = ftp_strdup(getoptionvalue("anonpass"));
         }          }
   
         if (ruserpass(host, &user, &pass, &acct) < 0) {          if (ruserpass(host, &fuser, &pass, &facct) < 0) {
                 code = -1;                  code = -1;
                 goto cleanup_ftp_login;                  goto cleanup_ftp_login;
         }          }
   
         while (user == NULL) {          while (fuser == NULL) {
                 if (localname)                  if (localname)
                         fprintf(ttyout, "Name (%s:%s): ", host, localname);                          fprintf(ttyout, "Name (%s:%s): ", host, localname);
                 else                  else
Line 414  ftp_login(const char *host, const char *
Line 414  ftp_login(const char *host, const char *
                         code = -1;                          code = -1;
                         goto cleanup_ftp_login;                          goto cleanup_ftp_login;
                 } else if (nlen == 0) {                  } else if (nlen == 0) {
                         user = ftp_strdup(localname);                          fuser = ftp_strdup(localname);
                 } else {                  } else {
                         user = ftp_strdup(tmp);                          fuser = ftp_strdup(tmp);
                 }                  }
         }          }
   
Line 424  ftp_login(const char *host, const char *
Line 424  ftp_login(const char *host, const char *
                 char *nuser;                  char *nuser;
                 size_t len;                  size_t len;
   
                 len = strlen(user) + 1 + strlen(host) + 1;                  len = strlen(fuser) + 1 + strlen(host) + 1;
                 nuser = ftp_malloc(len);                  nuser = ftp_malloc(len);
                 (void)strlcpy(nuser, user, len);                  (void)strlcpy(nuser, fuser, len);
                 (void)strlcat(nuser, "@",  len);                  (void)strlcat(nuser, "@",  len);
                 (void)strlcat(nuser, host, len);                  (void)strlcat(nuser, host, len);
                 FREEPTR(user);                  FREEPTR(fuser);
                 user = nuser;                  fuser = nuser;
         }          }
   
         n = command("USER %s", user);          n = command("USER %s", fuser);
         if (n == CONTINUE) {          if (n == CONTINUE) {
                 if (pass == NULL) {                  if (pass == NULL) {
                         p = getpass("Password: ");                          p = getpass("Password: ");
Line 447  ftp_login(const char *host, const char *
Line 447  ftp_login(const char *host, const char *
         }          }
         if (n == CONTINUE) {          if (n == CONTINUE) {
                 aflag++;                  aflag++;
                 if (acct == NULL) {                  if (facct == NULL) {
                         p = getpass("Account: ");                          p = getpass("Account: ");
                         if (p == NULL)                          if (p == NULL)
                                 p = emptypass;                                  p = emptypass;
                         acct = ftp_strdup(p);                          facct = ftp_strdup(p);
                         memset(p, 0, strlen(p));                          memset(p, 0, strlen(p));
                 }                  }
                 if (acct[0] == '\0') {                  if (facct[0] == '\0') {
                         warnx("Login failed");                          warnx("Login failed");
                         goto cleanup_ftp_login;                          goto cleanup_ftp_login;
                 }                  }
                 n = command("ACCT %s", acct);                  n = command("ACCT %s", facct);
                 memset(acct, 0, strlen(acct));                  memset(facct, 0, strlen(facct));
         }          }
         if ((n != COMPLETE) ||          if ((n != COMPLETE) ||
             (!aflag && acct != NULL && command("ACCT %s", acct) != COMPLETE)) {              (!aflag && facct != NULL && command("ACCT %s", facct) != COMPLETE)) {
                 warnx("Login failed");                  warnx("Login failed");
                 goto cleanup_ftp_login;                  goto cleanup_ftp_login;
         }          }
         rval = 1;          rval = 1;
         username = ftp_strdup(user);          username = ftp_strdup(fuser);
         if (proxy)          if (proxy)
                 goto cleanup_ftp_login;                  goto cleanup_ftp_login;
   
Line 485  ftp_login(const char *host, const char *
Line 485  ftp_login(const char *host, const char *
         updateremotecwd();          updateremotecwd();
   
  cleanup_ftp_login:   cleanup_ftp_login:
         FREEPTR(user);          FREEPTR(fuser);
         if (pass != NULL)          if (pass != NULL)
                 memset(pass, 0, strlen(pass));                  memset(pass, 0, strlen(pass));
         FREEPTR(pass);          FREEPTR(pass);
         if (acct != NULL)          if (facct != NULL)
                 memset(acct, 0, strlen(acct));                  memset(facct, 0, strlen(facct));
         FREEPTR(acct);          FREEPTR(facct);
         return (rval);          return (rval);
 }  }
   
Line 502  ftp_login(const char *host, const char *
Line 502  ftp_login(const char *host, const char *
  * Returns false if no new arguments have been added.   * Returns false if no new arguments have been added.
  */   */
 int  int
 another(int *pargc, char ***pargv, const char *prompt)  another(int *pargc, char ***pargv, const char *aprompt)
 {  {
         const char      *errormsg;          const char      *errormsg;
         int             ret, nlen;          int             ret, nlen;
Line 513  another(int *pargc, char ***pargv, const
Line 513  another(int *pargc, char ***pargv, const
                 fputs("Sorry, arguments too long.\n", ttyout);                  fputs("Sorry, arguments too long.\n", ttyout);
                 intr(0);                  intr(0);
         }          }
         fprintf(ttyout, "(%s) ", prompt);          fprintf(ttyout, "(%s) ", aprompt);
         line[len++] = ' ';          line[len++] = ' ';
         errormsg = NULL;          errormsg = NULL;
         nlen = getline(stdin, line + len, sizeof(line)-len, &errormsg);          nlen = getline(stdin, line + len, sizeof(line)-len, &errormsg);
Line 543  remglob(char *argv[], int doswitch, cons
Line 543  remglob(char *argv[], int doswitch, cons
         char temp[MAXPATHLEN];          char temp[MAXPATHLEN];
         int oldverbose, oldhash, oldprogress, fd;          int oldverbose, oldhash, oldprogress, fd;
         char *cp;          char *cp;
         const char *mode;          const char *rmode;
         size_t len;          size_t len;
   
         if (!mflag || !connected) {          if (!mflag || !connected) {
Line 582  remglob(char *argv[], int doswitch, cons
Line 582  remglob(char *argv[], int doswitch, cons
                 progress = 0;                  progress = 0;
                 if (doswitch)                  if (doswitch)
                         pswitch(!proxy);                          pswitch(!proxy);
                 for (mode = "w"; *++argv != NULL; mode = "a")                  for (rmode = "w"; *++argv != NULL; rmode = "a")
                         recvrequest("NLST", temp, *argv, mode, 0, 0);                          recvrequest("NLST", temp, *argv, rmode, 0, 0);
                 if ((code / 100) != COMPLETE) {                  if ((code / 100) != COMPLETE) {
                         if (errbuf != NULL)                          if (errbuf != NULL)
                                 *errbuf = reply_string;                                  *errbuf = reply_string;

Legend:
Removed from v.1.148  
changed lines
  Added in v.1.149

CVSweb <webmaster@jp.NetBSD.org>