(some of) my favorite fixes, review changes
authorMike Karels <karels@ucbvax.Berkeley.EDU>
Thu, 2 Mar 1989 06:25:47 +0000 (22:25 -0800)
committerMike Karels <karels@ucbvax.Berkeley.EDU>
Thu, 2 Mar 1989 06:25:47 +0000 (22:25 -0800)
SCCS-vsn: usr.bin/ftp/cmds.c 5.14
SCCS-vsn: usr.bin/ftp/cmdtab.c 5.8
SCCS-vsn: usr.bin/ftp/ftp.1 6.12
SCCS-vsn: usr.bin/ftp/ftp.c 5.24
SCCS-vsn: usr.bin/ftp/ruserpass.c 1.8

usr/src/usr.bin/ftp/cmds.c
usr/src/usr.bin/ftp/cmdtab.c
usr/src/usr.bin/ftp/ftp.1
usr/src/usr.bin/ftp/ftp.c
usr/src/usr.bin/ftp/ruserpass.c

index 00dea2d..764d7c6 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)cmds.c     5.13 (Berkeley) %G%";
+static char sccsid[] = "@(#)cmds.c     5.14 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
  * FTP User Program -- Command Routines.
  */
 #endif /* not lint */
 
 /*
  * FTP User Program -- Command Routines.
  */
-#include "ftp_var.h"
+#include <sys/param.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
 #include <sys/socket.h>
 
 #include <arpa/ftp.h>
 #include <sys/socket.h>
 
 #include <arpa/ftp.h>
@@ -33,9 +35,8 @@ static char sccsid[] = "@(#)cmds.c    5.13 (Berkeley) %G%";
 #include <netdb.h>
 #include <ctype.h>
 #include <time.h>
 #include <netdb.h>
 #include <ctype.h>
 #include <time.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <sys/param.h>
+
+#include "ftp_var.h"
 
 
 extern char *globerr;
 
 
 extern char *globerr;
@@ -98,13 +99,16 @@ setpeer(argc, argv)
                connected = 1;
                if (autologin) {
                        int overbose;
                connected = 1;
                if (autologin) {
                        int overbose;
+
                        (void) login(argv[1]);
 #if defined(unix) && NBBY == 8
 /*
  * this ifdef is to keep someone form "porting" this to an incompatible
  * system and not checking this out. This way they have to think about it.
  */
                        (void) login(argv[1]);
 #if defined(unix) && NBBY == 8
 /*
  * this ifdef is to keep someone form "porting" this to an incompatible
  * system and not checking this out. This way they have to think about it.
  */
-                       overbose = verbose, verbose = -1;
+                       overbose = verbose;
+                       if (debug == 0)
+                               verbose = -1;
                        if (command("SYST") == COMPLETE && overbose) {
                                register char *cp, c;
                                cp = index(reply_string+4, ' ');
                        if (command("SYST") == COMPLETE && overbose) {
                                register char *cp, c;
                                cp = index(reply_string+4, ' ');
@@ -125,11 +129,12 @@ setpeer(argc, argv)
                        if (!strncmp(reply_string, "215 UNIX Type: L8", 17)) {
                                setbinary();
                                if (overbose)
                        if (!strncmp(reply_string, "215 UNIX Type: L8", 17)) {
                                setbinary();
                                if (overbose)
-                                       printf("Using %s mode to transfer files.\n",
-                                               typename);
+                                   printf("Using %s mode to transfer files.\n",
+                                       typename);
                        } else if (overbose && 
                            !strncmp(reply_string, "215 TOPS20", 10)) {
                        } else if (overbose && 
                            !strncmp(reply_string, "215 TOPS20", 10)) {
-                               printf("Remember to set tenex mode when transfering binary files from this machine.\n");
+                               printf(
+"Remember to set tenex mode when transfering binary files from this machine.\n");
                        }
                        verbose = overbose;
 #endif /* unix */
                        }
                        verbose = overbose;
 #endif /* unix */
@@ -503,7 +508,7 @@ getit(argc, argv, restartit, mode)
 usage:
                printf("usage: %s remote-file [ local-file ]\n", argv[0]);
                code = -1;
 usage:
                printf("usage: %s remote-file [ local-file ]\n", argv[0]);
                code = -1;
-               return 0;
+               return (0);
        }
        if (argc < 3) {
                (void) strcat(line, " ");
        }
        if (argc < 3) {
                (void) strcat(line, " ");
@@ -517,7 +522,7 @@ usage:
                goto usage;
        if (!globulize(&argv[2])) {
                code = -1;
                goto usage;
        if (!globulize(&argv[2])) {
                code = -1;
-               return 0;
+               return (0);
        }
        if (loc && mcase) {
                char *tp = argv[1], *tp2, tmpbuf[MAXPATHLEN];
        }
        if (loc && mcase) {
                char *tp = argv[1], *tp2, tmpbuf[MAXPATHLEN];
@@ -538,26 +543,28 @@ usage:
                        argv[2] = tmpbuf;
                }
        }
                        argv[2] = tmpbuf;
                }
        }
-       if (loc && ntflag) {
+       if (loc && ntflag)
                argv[2] = dotrans(argv[2]);
                argv[2] = dotrans(argv[2]);
-       }
-       if (loc && mapflag) {
+       if (loc && mapflag)
                argv[2] = domap(argv[2]);
                argv[2] = domap(argv[2]);
-       }
        if (restartit) {
                struct stat stbuf;
                int ret;
        if (restartit) {
                struct stat stbuf;
                int ret;
+
                ret = stat(argv[2], &stbuf);
                if (restartit == 1) {
                        if (ret < 0) {
                                perror(argv[2]);
                ret = stat(argv[2], &stbuf);
                if (restartit == 1) {
                        if (ret < 0) {
                                perror(argv[2]);
-                               return 0;
+                               return (0);
                        }
                        restart_point = stbuf.st_size;
                } else {
                        if (ret == 0) {
                                int overbose;
                        }
                        restart_point = stbuf.st_size;
                } else {
                        if (ret == 0) {
                                int overbose;
-                               overbose = verbose; verbose = -1;
+
+                               overbose = verbose;
+                               if (debug == 0)
+                                       verbose = -1;
                                if (command("MDTM %s", argv[1]) == COMPLETE) {
                                        int yy, mo, day, hour, min, sec;
                                        struct tm *tm;
                                if (command("MDTM %s", argv[1]) == COMPLETE) {
                                        int yy, mo, day, hour, min, sec;
                                        struct tm *tm;
@@ -568,27 +575,27 @@ usage:
                                        tm = gmtime(&stbuf.st_mtime);
                                        tm->tm_mon++;
                                        if (tm->tm_year > yy%100)
                                        tm = gmtime(&stbuf.st_mtime);
                                        tm->tm_mon++;
                                        if (tm->tm_year > yy%100)
-                                               return 1;
+                                               return (1);
                                        else if (tm->tm_year == yy%100) {
                                                if (tm->tm_mon > mo)
                                        else if (tm->tm_year == yy%100) {
                                                if (tm->tm_mon > mo)
-                                                       return 1;
+                                                       return (1);
                                        } else if (tm->tm_mon == mo) {
                                                if (tm->tm_mday > day)
                                        } else if (tm->tm_mon == mo) {
                                                if (tm->tm_mday > day)
-                                                       return 1;
+                                                       return (1);
                                        } else if (tm->tm_mday == day) {
                                                if (tm->tm_hour > hour)
                                        } else if (tm->tm_mday == day) {
                                                if (tm->tm_hour > hour)
-                                                       return 1;
+                                                       return (1);
                                        } else if (tm->tm_hour == hour) {
                                                if (tm->tm_min > min)
                                        } else if (tm->tm_hour == hour) {
                                                if (tm->tm_min > min)
-                                                       return 1;
+                                                       return (1);
                                        } else if (tm->tm_min == min) {
                                                if (tm->tm_sec > sec)
                                        } else if (tm->tm_min == min) {
                                                if (tm->tm_sec > sec)
-                                                       return 1;
+                                                       return (1);
                                        }
                                } else {
                                        fputs(reply_string, stdout);
                                        verbose = overbose;
                                        }
                                } else {
                                        fputs(reply_string, stdout);
                                        verbose = overbose;
-                                       return 0;
+                                       return (0);
                                }
                        }
                }
                                }
                        }
                }
@@ -596,7 +603,7 @@ usage:
 
        recvrequest("RETR", argv[2], argv[1], mode);
        restart_point = 0;
 
        recvrequest("RETR", argv[2], argv[1], mode);
        restart_point = 0;
-       return 0;
+       return (0);
 }
 
 mabort()
 }
 
 mabort()
@@ -1160,7 +1167,7 @@ mls(argc, argv)
                        code = -1;
                        return;
        }
                        code = -1;
                        return;
        }
-       cmd = argv[0][1] == 'n' ? "NLST" : "LIST";
+       cmd = argv[0][1] == 'l' ? "NLST" : "LIST";
        mname = argv[0];
        mflag = 1;
        oldintr = signal(SIGINT, mabort);
        mname = argv[0];
        mflag = 1;
        oldintr = signal(SIGINT, mabort);
@@ -1893,8 +1900,8 @@ restart(argc, argv)
                printf("restart: offset not specified\n");
        else {
                restart_point = atol(argv[1]);
                printf("restart: offset not specified\n");
        else {
                restart_point = atol(argv[1]);
-               printf("restarting at %ld. execute get, put or append to initiate transfer\n",
-                       restart_point);
+               printf("restarting at %ld. %s\n", restart_point,
+                   "execute get, put or append to initiate transfer");
        }
 }
 
        }
 }
 
@@ -2016,7 +2023,9 @@ modtime(argc, argv)
                code = -1;
                return;
        }
                code = -1;
                return;
        }
-       overbose = verbose; verbose = -1;
+       overbose = verbose;
+       if (debug == 0)
+               verbose = -1;
        if (command("MDTM %s", argv[1]) == COMPLETE) {
                int yy, mo, day, hour, min, sec;
                sscanf(reply_string, "%*s %04d%02d%02d%02d%02d%02d", &yy, &mo,
        if (command("MDTM %s", argv[1]) == COMPLETE) {
                int yy, mo, day, hour, min, sec;
                sscanf(reply_string, "%*s %04d%02d%02d%02d%02d%02d", &yy, &mo,
index 2d2ad3f..4c6d884 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)cmdtab.c   5.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)cmdtab.c   5.8 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ftp_var.h"
 #endif /* not lint */
 
 #include "ftp_var.h"
@@ -149,8 +149,8 @@ struct cmd cmdtab[] = {
        { "quote",      quotehelp,      1,      1,      1,      quote },
        { "recv",       receivehelp,    1,      1,      1,      get },
        { "reget",      regethelp,      1,      1,      1,      reget },
        { "quote",      quotehelp,      1,      1,      1,      quote },
        { "recv",       receivehelp,    1,      1,      1,      get },
        { "reget",      regethelp,      1,      1,      1,      reget },
-       { "remotestatus",rmtstatushelp, 0,      1,      1,      rmtstatus },
-       { "remotehelp", remotehelp,     0,      1,      1,      rmthelp },
+       { "rstatus",    rmtstatushelp,  0,      1,      1,      rmtstatus },
+       { "rhelp",      remotehelp,     0,      1,      1,      rmthelp },
        { "rename",     renamehelp,     0,      1,      1,      renamefile },
        { "reset",      resethelp,      0,      1,      1,      reset },
        { "restart",    restarthelp,    1,      1,      1,      restart },
        { "rename",     renamehelp,     0,      1,      1,      renamefile },
        { "reset",      resethelp,      0,      1,      1,      reset },
        { "restart",    restarthelp,    1,      1,      1,      restart },
index 290e8e3..ab9a9f0 100644 (file)
@@ -13,7 +13,7 @@
 .\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 .\"
 .\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 .\"
-.\"    @(#)ftp.1       6.11 (Berkeley) %G%
+.\"    @(#)ftp.1       6.12 (Berkeley) %G%
 .\"
 .TH FTP 1 "February 23, 1989"
 .UC 5
 .\"
 .TH FTP 1 "February 23, 1989"
 .UC 5
@@ -244,7 +244,12 @@ is specified, the user's home directory is used.
 .TP
 \fBls\fP [ \fIremote-directory\fP ] [ \fIlocal-file\fP ]
 Print a listing of the contents of a
 .TP
 \fBls\fP [ \fIremote-directory\fP ] [ \fIlocal-file\fP ]
 Print a listing of the contents of a
-directory on the remote machine.  If
+directory on the remote machine.
+The listing includes any system-dependent information that the server
+chooses to include; for example, most UNIX systems will produce
+output from the command \*(lqls -l\*(rq.
+(See also \fBnlist\fP.)
+If
 .I remote-directory
 is left unspecified, the current working directory is used.
 If interactive prompting is on,
 .I remote-directory
 is left unspecified, the current working directory is used.
 If interactive prompting is on,
@@ -307,7 +312,8 @@ new local directories can be created with `\fB!\fP\ mkdir\ directory'.
 Make a directory on the remote machine.
 .TP
 \fBmls\fP \fIremote-files\fP \fIlocal-file\fP
 Make a directory on the remote machine.
 .TP
 \fBmls\fP \fIremote-files\fP \fIlocal-file\fP
-Like \fBls\fP, except multiple remote files may be specified.
+Like \fBnlist\fP, except multiple remote files may be specified,
+and the \fIlocal-file\fP must be specified.
 If interactive prompting is on,
 .I ftp
 will prompt the user to verify that the last argument is indeed the
 If interactive prompting is on,
 .I ftp
 will prompt the user to verify that the last argument is indeed the
@@ -338,11 +344,11 @@ settings.
 \fBnewer\fP \fIfile-name\fP
 Get the file only if the modification time of the remote file is more
 recent that the file on the current system. If the file does not
 \fBnewer\fP \fIfile-name\fP
 Get the file only if the modification time of the remote file is more
 recent that the file on the current system. If the file does not
-exist on the current syste, the remote file is considered \fInewer\fP.
+exist on the current system, the remote file is considered \fInewer\fP.
 Otherwise, this command is identical to \fBget\fP.
 .TP
 \fBnlist\fP [ \fIremote-directory\fP ] [ \fIlocal-file\fP ]
 Otherwise, this command is identical to \fBget\fP.
 .TP
 \fBnlist\fP [ \fIremote-directory\fP ] [ \fIlocal-file\fP ]
-Print an abbreviated listing of the contents of a
+Print a  list of the files of a
 directory on the remote machine.  If
 .I remote-directory
 is left unspecified, the current working directory is used.
 directory on the remote machine.  If
 .I remote-directory
 is left unspecified, the current working directory is used.
@@ -836,11 +842,16 @@ command argument.
 Once a match is made, the subsequent .netrc tokens are processed,
 stopping when the end of file is reached or another
 .B machine
 Once a match is made, the subsequent .netrc tokens are processed,
 stopping when the end of file is reached or another
 .B machine
+or a
+.B default
 token is encountered.
 .TP
 token is encountered.
 .TP
-\fBdefault\fP \fIname\fP
-This is the same as \fBmachine\fP except that \fBdefault\fP always
-matches the machine \fIname\fP. This is normally used as:
+\fBdefault\fP
+This is the same as \fBmachine\fP \fIname\fP except that \fBdefault\fP
+matches any name.
+There can be only one \fBdefault\fP token, and it must be after all
+\fBmachine\fP tokens.
+This is normally used as:
 .ce
 default login anonymous password user@site
 thereby giving the user \fIautomatic\fP anonymous ftp login to
 .ce
 default login anonymous password user@site
 thereby giving the user \fIautomatic\fP anonymous ftp login to
@@ -857,7 +868,8 @@ Supply a password.
 If this token is present, the auto-login process will supply the
 specified string if the remote server requires a password as part
 of the login process.
 If this token is present, the auto-login process will supply the
 specified string if the remote server requires a password as part
 of the login process.
-Note that if this token is present in the .netrc file,
+Note that if this token is present in the .netrc file for any user other
+than \fIanonymous\fP,
 .I ftp
 will abort the auto-login process if the .netrc is readable by
 anyone besides the user.
 .I ftp
 will abort the auto-login process if the .netrc is readable by
 anyone besides the user.
index caf501c..433a71d 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ftp.c      5.23 (Berkeley) %G%";
+static char sccsid[] = "@(#)ftp.c      5.24 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
-#include "ftp_var.h"
-
+#include <sys/param.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <sys/time.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <sys/time.h>
-#include <sys/param.h>
 #include <sys/file.h>
 
 #include <netinet/in.h>
 #include <sys/file.h>
 
 #include <netinet/in.h>
@@ -39,6 +37,8 @@ static char sccsid[] = "@(#)ftp.c     5.23 (Berkeley) %G%";
 #include <fcntl.h>
 #include <pwd.h>
 
 #include <fcntl.h>
 #include <pwd.h>
 
+#include "ftp_var.h"
+
 struct sockaddr_in hisctladdr;
 struct sockaddr_in data_addr;
 int    data = -1;
 struct sockaddr_in hisctladdr;
 struct sockaddr_in data_addr;
 int    data = -1;
@@ -65,9 +65,8 @@ hookup(host, port)
        hisctladdr.sin_addr.s_addr = inet_addr(host);
        if (hisctladdr.sin_addr.s_addr != -1) {
                hisctladdr.sin_family = AF_INET;
        hisctladdr.sin_addr.s_addr = inet_addr(host);
        if (hisctladdr.sin_addr.s_addr != -1) {
                hisctladdr.sin_family = AF_INET;
-               (void) strcpy(hostnamebuf, host);
-       }
-       else {
+               (void) strncpy(hostnamebuf, host, sizeof(hostnamebuf));
+       } else {
                hp = gethostbyname(host);
                if (hp == NULL) {
                        fprintf(stderr, "ftp: %s: ", host);
                hp = gethostbyname(host);
                if (hp == NULL) {
                        fprintf(stderr, "ftp: %s: ", host);
@@ -78,7 +77,7 @@ hookup(host, port)
                hisctladdr.sin_family = hp->h_addrtype;
                bcopy(hp->h_addr_list[0],
                    (caddr_t)&hisctladdr.sin_addr, hp->h_length);
                hisctladdr.sin_family = hp->h_addrtype;
                bcopy(hp->h_addr_list[0],
                    (caddr_t)&hisctladdr.sin_addr, hp->h_length);
-               (void) strcpy(hostnamebuf, hp->h_name);
+               (void) strncpy(hostnamebuf, hp->h_name, sizeof(hostnamebuf));
        }
        hostname = hostnamebuf;
        s = socket(hisctladdr.sin_family, SOCK_STREAM, 0);
        }
        hostname = hostnamebuf;
        s = socket(hisctladdr.sin_family, SOCK_STREAM, 0);
@@ -167,7 +166,6 @@ login(host)
 
        user = pass = acct = 0;
        if (ruserpass(host, &user, &pass, &acct) < 0) {
 
        user = pass = acct = 0;
        if (ruserpass(host, &user, &pass, &acct) < 0) {
-               disconnect();
                code = -1;
                return(0);
        }
                code = -1;
                return(0);
        }
@@ -283,13 +281,13 @@ getreply(expecteof)
                                case WILL:
                                case WONT:
                                        c = getc(cin);
                                case WILL:
                                case WONT:
                                        c = getc(cin);
-                                       fprintf(cout, "%c%c%c",IAC,WONT,c);
+                                       fprintf(cout, "%c%c%c",IAC,DONT,c);
                                        (void) fflush(cout);
                                        break;
                                case DO:
                                case DONT:
                                        c = getc(cin);
                                        (void) fflush(cout);
                                        break;
                                case DO:
                                case DONT:
                                        c = getc(cin);
-                                       fprintf(cout, "%c%c%c",IAC,DONT,c);
+                                       fprintf(cout, "%c%c%c",IAC,WONT,c);
                                        (void) fflush(cout);
                                        break;
                                default:
                                        (void) fflush(cout);
                                        break;
                                default:
@@ -386,6 +384,8 @@ abortsend()
        longjmp(sendabort, 1);
 }
 
        longjmp(sendabort, 1);
 }
 
+#define HASHBYTES 1024
+
 sendrequest(cmd, local, remote)
        char *cmd, *local, *remote;
 {
 sendrequest(cmd, local, remote)
        char *cmd, *local, *remote;
 {
@@ -393,7 +393,7 @@ sendrequest(cmd, local, remote)
        int (*closefunc)(), pclose(), fclose(), (*oldintr)(), (*oldintp)();
        int abortsend();
        char buf[BUFSIZ];
        int (*closefunc)(), pclose(), fclose(), (*oldintr)(), (*oldintp)();
        int abortsend();
        char buf[BUFSIZ];
-       long bytes = 0, hashbytes = sizeof (buf);
+       long bytes = 0, hashbytes = HASHBYTES;
        register int c, d;
        struct stat st;
        struct timeval start, stop;
        register int c, d;
        struct stat st;
        struct timeval start, stop;
@@ -519,11 +519,16 @@ sendrequest(cmd, local, remote)
                                break;
                        bytes += c;
                        if (hash) {
                                break;
                        bytes += c;
                        if (hash) {
-                               (void) putchar('#');
+                               while (bytes >= hashbytes) {
+                                       (void) putchar('#');
+                                       hashbytes += HASHBYTES;
+                               }
                                (void) fflush(stdout);
                        }
                }
                if (hash && bytes > 0) {
                                (void) fflush(stdout);
                        }
                }
                if (hash && bytes > 0) {
+                       if (bytes < HASHBYTES)
+                               (void) putchar('#');
                        (void) putchar('\n');
                        (void) fflush(stdout);
                }
                        (void) putchar('\n');
                        (void) fflush(stdout);
                }
@@ -542,7 +547,7 @@ sendrequest(cmd, local, remote)
                                while (hash && (bytes >= hashbytes)) {
                                        (void) putchar('#');
                                        (void) fflush(stdout);
                                while (hash && (bytes >= hashbytes)) {
                                        (void) putchar('#');
                                        (void) fflush(stdout);
-                                       hashbytes += sizeof (buf);
+                                       hashbytes += HASHBYTES;
                                }
                                if (ferror(dout))
                                        break;
                                }
                                if (ferror(dout))
                                        break;
@@ -623,11 +628,14 @@ recvrequest(cmd, local, remote, mode)
        FILE *fout, *din = 0, *popen();
        int (*closefunc)(), pclose(), fclose(), (*oldintr)(), (*oldintp)(); 
        int abortrecv(), oldverbose, oldtype = 0, is_retr, tcrflag, nfnd;
        FILE *fout, *din = 0, *popen();
        int (*closefunc)(), pclose(), fclose(), (*oldintr)(), (*oldintp)(); 
        int abortrecv(), oldverbose, oldtype = 0, is_retr, tcrflag, nfnd;
-       char buf[BUFSIZ], *gunique(), msg;
-       long bytes = 0, hashbytes = sizeof (buf);
+       char *buf, *gunique(), msg;
+       static int bufsize;
+       long bytes = 0, hashbytes = HASHBYTES;
        struct fd_set mask;
        register int c, d;
        struct timeval start, stop;
        struct fd_set mask;
        register int c, d;
        struct timeval start, stop;
+       struct stat st;
+       extern char *malloc();
 
        is_retr = strcmp(cmd, "RETR") == 0;
        if (proxy && is_retr) {
 
        is_retr = strcmp(cmd, "RETR") == 0;
        if (proxy && is_retr) {
@@ -769,8 +777,7 @@ recvrequest(cmd, local, remote, mode)
                        goto abort;
                }
                closefunc = pclose;
                        goto abort;
                }
                closefunc = pclose;
-       }
-       else {
+       } else {
                fout = fopen(local, mode);
                if (fout == NULL) {
                        perror(local);
                fout = fopen(local, mode);
                if (fout == NULL) {
                        perror(local);
@@ -778,6 +785,18 @@ recvrequest(cmd, local, remote, mode)
                }
                closefunc = fclose;
        }
                }
                closefunc = fclose;
        }
+       if (fstat(fileno(fout), &st) < 0 || st.st_blksize == 0)
+               st.st_blksize = BUFSIZ;
+       if (st.st_blksize > bufsize) {
+               if (buf)
+                       (void) free(buf);
+               buf = malloc(st.st_blksize);
+               if (buf == NULL) {
+                       perror("malloc");
+                       goto abort;
+               }
+               bufsize = st.st_blksize;
+       }
        (void) gettimeofday(&start, (struct timezone *)0);
        switch (type) {
 
        (void) gettimeofday(&start, (struct timezone *)0);
        switch (type) {
 
@@ -791,16 +810,21 @@ recvrequest(cmd, local, remote, mode)
                        return;
                }
                errno = d = 0;
                        return;
                }
                errno = d = 0;
-               while ((c = read(fileno(din), buf, sizeof (buf))) > 0) {
+               while ((c = read(fileno(din), buf, bufsize)) > 0) {
                        if ((d = write(fileno(fout), buf, c)) != c)
                                break;
                        bytes += c;
                        if (hash) {
                        if ((d = write(fileno(fout), buf, c)) != c)
                                break;
                        bytes += c;
                        if (hash) {
-                               (void) putchar('#');
+                               while (bytes >= hashbytes) {
+                                       (void) putchar('#');
+                                       hashbytes += HASHBYTES;
+                               }
                                (void) fflush(stdout);
                        }
                }
                if (hash && bytes > 0) {
                                (void) fflush(stdout);
                        }
                }
                if (hash && bytes > 0) {
+                       if (bytes < HASHBYTES)
+                               (void) putchar('#');
                        (void) putchar('\n');
                        (void) fflush(stdout);
                }
                        (void) putchar('\n');
                        (void) fflush(stdout);
                }
@@ -816,11 +840,12 @@ recvrequest(cmd, local, remote, mode)
        case TYPE_A:
                if (restart_point) {
                        register int i, n, c;
        case TYPE_A:
                if (restart_point) {
                        register int i, n, c;
+
                        if (fseek(fout, 0L, L_SET) < 0)
                                goto done;
                        n = restart_point;
                        i = 0;
                        if (fseek(fout, 0L, L_SET) < 0)
                                goto done;
                        n = restart_point;
                        i = 0;
-                       while(i++ < n) {
+                       while (i++ < n) {
                                if ((c=getc(fout)) == EOF)
                                        goto done;
                                if (c == '\n')
                                if ((c=getc(fout)) == EOF)
                                        goto done;
                                if (c == '\n')
@@ -839,30 +864,34 @@ done:
                                while (hash && (bytes >= hashbytes)) {
                                        (void) putchar('#');
                                        (void) fflush(stdout);
                                while (hash && (bytes >= hashbytes)) {
                                        (void) putchar('#');
                                        (void) fflush(stdout);
-                                       hashbytes += sizeof (buf);
+                                       hashbytes += HASHBYTES;
                                }
                                bytes++;
                                if ((c = getc(din)) != '\n' || tcrflag) {
                                }
                                bytes++;
                                if ((c = getc(din)) != '\n' || tcrflag) {
-                                       if (ferror (fout))
-                                               break;
-                                       (void) putc ('\r', fout);
+                                       if (ferror(fout))
+                                               goto break2;
+                                       (void) putc('\r', fout);
+                                       if (c == '\0' || c == EOF)
+                                               goto contin2;
                                }
                        }
                                }
                        }
-                       (void) putc (c, fout);
+                       (void) putc(c, fout);
                        bytes++;
                        bytes++;
+       contin2:        ;
                }
                }
+break2:
                if (hash) {
                        if (bytes < hashbytes)
                                (void) putchar('#');
                        (void) putchar('\n');
                        (void) fflush(stdout);
                }
                if (hash) {
                        if (bytes < hashbytes)
                                (void) putchar('#');
                        (void) putchar('\n');
                        (void) fflush(stdout);
                }
-               if (ferror (din)){
+               if (ferror(din)){
                        if (errno != EPIPE)
                                perror ("netin");
                        bytes = -1;
                }
                        if (errno != EPIPE)
                                perror ("netin");
                        bytes = -1;
                }
-               if (ferror (fout))
+               if (ferror(fout))
                        perror (local);
                break;
        }
                        perror (local);
                break;
        }
@@ -946,7 +975,7 @@ abort:
                lostpeer();
        }
        if (din && FD_ISSET(fileno(din), &mask)) {
                lostpeer();
        }
        if (din && FD_ISSET(fileno(din), &mask)) {
-               while ((c = read(fileno(din), buf, sizeof (buf))) > 0)
+               while ((c = read(fileno(din), buf, bufsize)) > 0)
                        ;
        }
        if ((c = getreply(0)) == ERROR && code == 552) { /* needed for nic style abort */
                        ;
        }
        if ((c = getreply(0)) == ERROR && code == 552) { /* needed for nic style abort */
index 396b85f..40f45af 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ruserpass.c        1.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)ruserpass.c        1.8 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
-struct macel {
-       char mac_name[9];       /* macro name */
-       char *mac_start;        /* start of macro in macbuf */
-       char *mac_end;          /* end of macro in macbuf */
-};
-
-extern int macnum, proxy;                      /* number of defined macros */
-extern struct macel macros[16], *macpt;
-extern char macbuf[4096];
-
 #include <sys/types.h>
 #include <stdio.h>
 #include <utmp.h>
 #include <ctype.h>
 #include <sys/stat.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <stdio.h>
 #include <utmp.h>
 #include <ctype.h>
 #include <sys/stat.h>
 #include <errno.h>
+#include "ftp_var.h"
 
 char   *renvlook(), *malloc(), *index(), *getenv(), *getpass(), *getlogin();
 char   *strcpy();
 struct utmp *getutmp();
 static FILE *cfile;
 
 
 char   *renvlook(), *malloc(), *index(), *getenv(), *getpass(), *getlogin();
 char   *strcpy();
 struct utmp *getutmp();
 static FILE *cfile;
 
-ruserpass(host, aname, apass, aacct)
-       char *host, **aname, **apass, **aacct;
-{
-
-       /* renv(host, aname, apass, aacct);
-       if (*aname == 0 || *apass == 0) */
-               return(rnetrc(host, aname, apass, aacct));
-}
-
 #define        DEFAULT 1
 #define        LOGIN   2
 #define        PASSWD  3
 #define        ACCOUNT 4
 #define MACDEF  5
 #define        ID      10
 #define        DEFAULT 1
 #define        LOGIN   2
 #define        PASSWD  3
 #define        ACCOUNT 4
 #define MACDEF  5
 #define        ID      10
-#define        MACHINE 11
+#define        MACH    11
 
 static char tokval[100];
 
 
 static char tokval[100];
 
@@ -67,17 +49,18 @@ static struct toktab {
        "default",      DEFAULT,
        "login",        LOGIN,
        "password",     PASSWD,
        "default",      DEFAULT,
        "login",        LOGIN,
        "password",     PASSWD,
+       "passwd",       PASSWD,
        "account",      ACCOUNT,
        "account",      ACCOUNT,
-       "machine",      MACHINE,
+       "machine",      MACH,
        "macdef",       MACDEF,
        0,              0
 };
 
        "macdef",       MACDEF,
        0,              0
 };
 
-static
-rnetrc(host, aname, apass, aacct)
+ruserpass(host, aname, apass, aacct)
        char *host, **aname, **apass, **aacct;
 {
        char *hdir, buf[BUFSIZ], *tmp;
        char *host, **aname, **apass, **aacct;
 {
        char *hdir, buf[BUFSIZ], *tmp;
+       char myname[MAXHOSTNAMELEN], *mydomain;
        int t, i, c, usedefault = 0;
        struct stat stb;
        extern int errno;
        int t, i, c, usedefault = 0;
        struct stat stb;
        extern int errno;
@@ -92,6 +75,10 @@ rnetrc(host, aname, apass, aacct)
                        perror(buf);
                return(0);
        }
                        perror(buf);
                return(0);
        }
+       if (gethostname(myname, sizeof(myname)) < 0)
+               myname[0] = '\0';
+       if ((mydomain = index(myname, '.')) == NULL)
+               mydomain = "";
 next:
        while ((t = token())) switch(t) {
 
 next:
        while ((t = token())) switch(t) {
 
@@ -99,10 +86,33 @@ next:
                usedefault = 1;
                /* FALL THROUGH */
 
                usedefault = 1;
                /* FALL THROUGH */
 
-       case MACHINE:
-               if (!usedefault && (token() != ID || strcmp(host, tokval)))
+       case MACH:
+               if (!usedefault) {
+                       if (token() != ID)
+                               continue;
+                       /*
+                        * Allow match either for user's input host name
+                        * or official hostname.  Also allow match of 
+                        * incompletely-specified host in local domain.
+                        */
+                       if (strcasecmp(host, tokval) == 0)
+                               goto match;
+                       if (strcasecmp(hostname, tokval) == 0)
+                               goto match;
+                       if ((tmp = index(hostname, '.')) != NULL &&
+                           strcasecmp(tmp, mydomain) == 0 &&
+                           strncasecmp(hostname, tokval, tmp-hostname) == 0 &&
+                           tokval[tmp - hostname] == '\0')
+                               goto match;
+                       if ((tmp = index(host, '.')) != NULL &&
+                           strcasecmp(tmp, mydomain) == 0 &&
+                           strncasecmp(host, tokval, tmp - host) == 0 &&
+                           tokval[tmp - host] == '\0')
+                               goto match;
                        continue;
                        continue;
-               while ((t = token()) && t != MACHINE) switch(t) {
+               }
+       match:
+               while ((t = token()) && t != MACH && t != DEFAULT) switch(t) {
 
                case LOGIN:
                        if (token())
 
                case LOGIN:
                        if (token())
@@ -115,11 +125,12 @@ next:
                                }
                        break;
                case PASSWD:
                                }
                        break;
                case PASSWD:
-                       if (fstat(fileno(cfile), &stb) >= 0
-                           && (stb.st_mode & 077) != 0) {
+                       if (strcmp(*aname, "anonymous") &&
+                           fstat(fileno(cfile), &stb) >= 0 &&
+                           (stb.st_mode & 077) != 0) {
        fprintf(stderr, "Error - .netrc file not correct mode.\n");
        fprintf(stderr, "Remove password or correct mode.\n");
        fprintf(stderr, "Error - .netrc file not correct mode.\n");
        fprintf(stderr, "Remove password or correct mode.\n");
-                               return(-1);
+                               goto bad;
                        }
                        if (token() && *apass == 0) {
                                *apass = malloc((unsigned) strlen(tokval) + 1);
                        }
                        if (token() && *apass == 0) {
                                *apass = malloc((unsigned) strlen(tokval) + 1);
@@ -131,7 +142,7 @@ next:
                            && (stb.st_mode & 077) != 0) {
        fprintf(stderr, "Error - .netrc file not correct mode.\n");
        fprintf(stderr, "Remove account or correct mode.\n");
                            && (stb.st_mode & 077) != 0) {
        fprintf(stderr, "Error - .netrc file not correct mode.\n");
        fprintf(stderr, "Remove account or correct mode.\n");
-                               return(-1);
+                               goto bad;
                        }
                        if (token() && *aacct == 0) {
                                *aacct = malloc((unsigned) strlen(tokval) + 1);
                        }
                        if (token() && *aacct == 0) {
                                *aacct = malloc((unsigned) strlen(tokval) + 1);
@@ -140,16 +151,17 @@ next:
                        break;
                case MACDEF:
                        if (proxy) {
                        break;
                case MACDEF:
                        if (proxy) {
+                               (void) fclose(cfile);
                                return(0);
                        }
                        while ((c=getc(cfile)) != EOF && c == ' ' || c == '\t');
                        if (c == EOF || c == '\n') {
                                printf("Missing macdef name argument.\n");
                                return(0);
                        }
                        while ((c=getc(cfile)) != EOF && c == ' ' || c == '\t');
                        if (c == EOF || c == '\n') {
                                printf("Missing macdef name argument.\n");
-                               return(-1);
+                               goto bad;
                        }
                        if (macnum == 16) {
                                printf("Limit of 16 macros have already been defined\n");
                        }
                        if (macnum == 16) {
                                printf("Limit of 16 macros have already been defined\n");
-                               return(-1);
+                               goto bad;
                        }
                        tmp = macros[macnum].mac_name;
                        *tmp++ = c;
                        }
                        tmp = macros[macnum].mac_name;
                        *tmp++ = c;
@@ -159,7 +171,7 @@ next:
                        }
                        if (c == EOF) {
                                printf("Macro definition missing null line terminator.\n");
                        }
                        if (c == EOF) {
                                printf("Macro definition missing null line terminator.\n");
-                               return(-1);
+                               goto bad;
                        }
                        *tmp = '\0';
                        if (c != '\n') {
                        }
                        *tmp = '\0';
                        if (c != '\n') {
@@ -167,7 +179,7 @@ next:
                        }
                        if (c == EOF) {
                                printf("Macro definition missing null line terminator.\n");
                        }
                        if (c == EOF) {
                                printf("Macro definition missing null line terminator.\n");
-                               return(-1);
+                               goto bad;
                        }
                        if (macnum == 0) {
                                macros[macnum].mac_start = macbuf;
                        }
                        if (macnum == 0) {
                                macros[macnum].mac_start = macbuf;
@@ -179,7 +191,7 @@ next:
                        while (tmp != macbuf + 4096) {
                                if ((c=getc(cfile)) == EOF) {
                                printf("Macro definition missing null line terminator.\n");
                        while (tmp != macbuf + 4096) {
                                if ((c=getc(cfile)) == EOF) {
                                printf("Macro definition missing null line terminator.\n");
-                                       return(-1);
+                                       goto bad;
                                }
                                *tmp = c;
                                if (*tmp == '\n') {
                                }
                                *tmp = c;
                                if (*tmp == '\n') {
@@ -193,7 +205,7 @@ next:
                        }
                        if (tmp == macbuf + 4096) {
                                printf("4K macro buffer exceeded\n");
                        }
                        if (tmp == macbuf + 4096) {
                                printf("4K macro buffer exceeded\n");
-                               return(-1);
+                               goto bad;
                        }
                        break;
                default:
                        }
                        break;
                default:
@@ -205,6 +217,9 @@ next:
 done:
        (void) fclose(cfile);
        return(0);
 done:
        (void) fclose(cfile);
        return(0);
+bad:
+       (void) fclose(cfile);
+       return(-1);
 }
 
 static
 }
 
 static