[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.144 and 1.144.6.1

version 1.144, 2007/12/05 03:46:34 version 1.144.6.1, 2008/05/18 12:36:05
Line 1 
Line 1 
 /*      $NetBSD$        */  /*      $NetBSD$        */
   
 /*-  /*-
  * Copyright (c) 1997-2007 The NetBSD Foundation, Inc.   * Copyright (c) 1997-2008 The NetBSD Foundation, Inc.
  * All rights reserved.   * All rights reserved.
  *   *
  * This code is derived from software contributed to The NetBSD Foundation   * This code is derived from software contributed to The NetBSD Foundation
Line 19 
Line 19 
  * 2. Redistributions in binary form must reproduce the above copyright   * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the   *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.   *    documentation and/or other materials provided with the distribution.
  * 3. All advertising materials mentioning features or use of this software  
  *    must display the following acknowledgement:  
  *      This product includes software developed by the NetBSD  
  *      Foundation, Inc. and its contributors.  
  * 4. Neither the name of The NetBSD Foundation nor the names of its  
  *    contributors may be used to endorse or promote products derived  
  *    from this software without specific prior written permission.  
  *   *
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS   * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
Line 310  cleanuppeer(void)
Line 303  cleanuppeer(void)
                 anonftp = 0;                  anonftp = 0;
         data = -1;          data = -1;
         epsv4bad = 0;          epsv4bad = 0;
           epsv6bad = 0;
         if (username)          if (username)
                 free(username);                  free(username);
         username = NULL;          username = NULL;
Line 871  fileindir(const char *file, const char *
Line 865  fileindir(const char *file, const char *
         if (realdir[0] != '/')          /* relative result is ok */          if (realdir[0] != '/')          /* relative result is ok */
                 return 1;                  return 1;
         dirlen = strlen(dir);          dirlen = strlen(dir);
 #if 0  
 printf("file %s parent %s realdir %s dir %s [%d]\n",  
     file, parentdir, realdir, dir, dirlen);  
 #endif  
         if (strncmp(realdir, dir, dirlen) == 0 &&          if (strncmp(realdir, dir, dirlen) == 0 &&
             (realdir[dirlen] == '/' || realdir[dirlen] == '\0'))              (realdir[dirlen] == '/' || realdir[dirlen] == '\0'))
                 return 1;                  return 1;
Line 1214  formatbuf(char *buf, size_t len, const c
Line 1204  formatbuf(char *buf, size_t len, const c
 }  }
   
 /*  /*
  * Parse `port' into a TCP port number, defaulting to `defport' if `port' is  
  * an unknown service name. If defport != -1, print a warning upon bad parse.  
  */  
 int  
 parseport(const char *port, int defport)  
 {  
         int      rv;  
         long     nport;  
         char    *p, *ep;  
   
         p = ftp_strdup(port);  
         nport = strtol(p, &ep, 10);  
         if (*ep != '\0' && ep == p) {  
                 struct servent  *svp;  
   
                 svp = getservbyname(port, "tcp");  
                 if (svp == NULL) {  
  badparseport:  
                         if (defport != -1)  
                                 warnx("Unknown port `%s', using port %d",  
                                     port, defport);  
                         rv = defport;  
                 } else  
                         rv = ntohs(svp->s_port);  
         } else if (nport < 1 || nport > MAX_IN_PORT_T || *ep != '\0')  
                 goto badparseport;  
         else  
                 rv = nport;  
         free(p);  
         return (rv);  
 }  
   
 /*  
  * Determine if given string is an IPv6 address or not.   * Determine if given string is an IPv6 address or not.
  * Return 1 for yes, 0 for no   * Return 1 for yes, 0 for no
  */   */
Line 1340  ftp_connect(int sock, const struct socka
Line 1297  ftp_connect(int sock, const struct socka
         struct timeval  endtime, now, td;          struct timeval  endtime, now, td;
         struct pollfd   pfd[1];          struct pollfd   pfd[1];
         char            hname[NI_MAXHOST];          char            hname[NI_MAXHOST];
           char            sname[NI_MAXSERV];
   
         setupsockbufsize(sock);          setupsockbufsize(sock);
         if (getnameinfo(name, namelen,          if (getnameinfo(name, namelen,
             hname, sizeof(hname), NULL, 0, NI_NUMERICHOST) != 0)              hname, sizeof(hname), sname, sizeof(sname),
               NI_NUMERICHOST | NI_NUMERICSERV) != 0) {
                 strlcpy(hname, "?", sizeof(hname));                  strlcpy(hname, "?", sizeof(hname));
                   strlcpy(sname, "?", sizeof(sname));
           }
   
         if (bindai != NULL) {                   /* bind to specific addr */          if (bindai != NULL) {                   /* bind to specific addr */
                 struct addrinfo *ai;                  struct addrinfo *ai;
Line 1371  ftp_connect(int sock, const struct socka
Line 1332  ftp_connect(int sock, const struct socka
   
                                                 /* save current socket flags */                                                  /* save current socket flags */
         if ((flags = fcntl(sock, F_GETFL, 0)) == -1) {          if ((flags = fcntl(sock, F_GETFL, 0)) == -1) {
                 warn("Can't %s socket flags for connect to `%s'",                  warn("Can't %s socket flags for connect to `%s:%s'",
                     "save", hname);                      "save", hname, sname);
                 return -1;                  return -1;
         }          }
                                                 /* set non-blocking connect */                                                  /* set non-blocking connect */
         if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) == -1) {          if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) == -1) {
                 warn("Can't set socket non-blocking for connect to `%s'",                  warn("Can't set socket non-blocking for connect to `%s:%s'",
                     hname);                      hname, sname);
                 return -1;                  return -1;
         }          }
   
Line 1396  ftp_connect(int sock, const struct socka
Line 1357  ftp_connect(int sock, const struct socka
         if (rv == -1) {                         /* connection error */          if (rv == -1) {                         /* connection error */
                 if (errno != EINPROGRESS) {     /* error isn't "please wait" */                  if (errno != EINPROGRESS) {     /* error isn't "please wait" */
  connecterror:   connecterror:
                         warn("Can't connect to `%s'", hname);                          warn("Can't connect to `%s:%s'", hname, sname);
                         return -1;                          return -1;
                 }                  }
   
Line 1441  ftp_connect(int sock, const struct socka
Line 1402  ftp_connect(int sock, const struct socka
   
         if (fcntl(sock, F_SETFL, flags) == -1) {          if (fcntl(sock, F_SETFL, flags) == -1) {
                                                 /* restore socket flags */                                                  /* restore socket flags */
                 warn("Can't %s socket flags for connect to `%s'",                  warn("Can't %s socket flags for connect to `%s:%s'",
                     "restore", hname);                      "restore", hname, sname);
                 return -1;                  return -1;
         }          }
         return 0;          return 0;

Legend:
Removed from v.1.144  
changed lines
  Added in v.1.144.6.1

CVSweb <webmaster@jp.NetBSD.org>