Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/libexec/ftpd * fix a problem in retrieve() where arguments t...



details:   https://anonhg.NetBSD.org/src/rev/bc871442f4e4
branches:  trunk
changeset: 473045:bc871442f4e4
user:      lukem <lukem%NetBSD.org@localhost>
date:      Tue May 18 08:14:17 1999 +0000

description:
* fix a problem in retrieve() where arguments to commands weren't working
  (this was broken in the last commit). problem noticed by simonb@
* don't display the stderr output of the internal ls.
* modify usage of lreply so that generally only one `XXX-' code per
  `block' is displayed; the rest of the lines have four spaces instead.
  i find this easier to read.
* fix a couple places where byte accounting wasn't correct

diffstat:

 libexec/ftpd/conf.c   |  12 +++++--
 libexec/ftpd/extern.h |   3 +-
 libexec/ftpd/ftpcmd.y |  23 +++++++++++-----
 libexec/ftpd/ftpd.c   |  69 ++++++++++++++++++++++++++++++++------------------
 libexec/ftpd/popen.c  |   6 ++--
 5 files changed, 72 insertions(+), 41 deletions(-)

diffs (truncated from 379 to 300 lines):

diff -r abcb588dbbd3 -r bc871442f4e4 libexec/ftpd/conf.c
--- a/libexec/ftpd/conf.c       Tue May 18 07:51:34 1999 +0000
+++ b/libexec/ftpd/conf.c       Tue May 18 08:14:17 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: conf.c,v 1.19 1999/05/17 15:14:54 lukem Exp $  */
+/*     $NetBSD: conf.c,v 1.20 1999/05/18 08:14:17 lukem Exp $  */
 
 /*-
  * Copyright (c) 1997, 1999 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: conf.c,v 1.19 1999/05/17 15:14:54 lukem Exp $");
+__RCSID("$NetBSD: conf.c,v 1.20 1999/05/18 08:14:17 lukem Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -351,13 +351,13 @@
                /* First check for a display file */
        if (curclass.display != NULL && curclass.display[0] &&
            (f = fopen(curclass.display, "r")) != NULL) {
+               lreply(code, "");
                while (fgets(line, BUFSIZ, f)) {
                        if ((cp = strchr(line, '\n')) != NULL)
                                *cp = '\0';
-                       lreply(code, "%s", line);
+                       lreply(0, "%s", line);
                }
                fclose(f);
-               lreply(code, "");
        }
 
                /* Now see if there are any notify files */
@@ -373,6 +373,10 @@
                if (!S_ISREG(st.st_mode))
                        continue;
                then = st.st_mtime;
+               if (code != 0) {
+                       lreply(code, "");
+                       code = 0;
+               }
                lreply(code, "Please read the file %s", *rlist);
                t = localtime(&now);
                age = 365 * t->tm_year + t->tm_yday;
diff -r abcb588dbbd3 -r bc871442f4e4 libexec/ftpd/extern.h
--- a/libexec/ftpd/extern.h     Tue May 18 07:51:34 1999 +0000
+++ b/libexec/ftpd/extern.h     Tue May 18 08:14:17 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.16 1999/05/17 15:14:54 lukem Exp $        */
+/*     $NetBSD: extern.h,v 1.17 1999/05/18 08:14:18 lukem Exp $        */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -129,3 +129,4 @@
 
 
 #define PLURAL(s)      ((s) == 1 ? "" : "s")
+#define        INTERNAL_LS     "/bin/ls"
diff -r abcb588dbbd3 -r bc871442f4e4 libexec/ftpd/ftpcmd.y
--- a/libexec/ftpd/ftpcmd.y     Tue May 18 07:51:34 1999 +0000
+++ b/libexec/ftpd/ftpcmd.y     Tue May 18 08:14:17 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftpcmd.y,v 1.27 1999/05/17 15:14:54 lukem Exp $        */
+/*     $NetBSD: ftpcmd.y,v 1.28 1999/05/18 08:14:18 lukem Exp $        */
 
 /*
  * Copyright (c) 1985, 1988, 1993, 1994
@@ -47,7 +47,7 @@
 #if 0
 static char sccsid[] = "@(#)ftpcmd.y   8.3 (Berkeley) 4/6/94";
 #else
-__RCSID("$NetBSD: ftpcmd.y,v 1.27 1999/05/17 15:14:54 lukem Exp $");
+__RCSID("$NetBSD: ftpcmd.y,v 1.28 1999/05/18 08:14:18 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -186,11 +186,12 @@
        | QUIT CRLF
                {
                        if (logged_in) {
-                               lreply(221,
+                               lreply(221, "");
+                               lreply(0,
            "Data traffic for this session was %qd byte%s in %qd file%s.",
                                    total_data, PLURAL(total_data),
                                    total_files, PLURAL(total_files));
-                               lreply(221,
+                               lreply(0,
            "Total traffic for this session was %qd byte%s in %qd transfer%s.",
                                    total_bytes, PLURAL(total_bytes),
                                    total_xfers, PLURAL(total_xfers));
@@ -203,10 +204,9 @@
                                    total_bytes, PLURAL(total_bytes),
                                    total_xfers, PLURAL(total_xfers));
                        }
-                       lreply(211,
+                       reply(221,
                            "Thank you for using the FTP service on %s.",
                            hostname);
-                       reply(221, "Goodbye.");
                        dologout(0);
                }
 
@@ -1414,14 +1414,15 @@
                int i, j, w;
                int columns, lines;
 
-               lreply(214, "The following %scommands are recognized.", type);
+               lreply(214, "");
+               lreply(0, "The following %scommands are recognized.", type);
                lreply(0, "(`-' = not implemented, `+' = supports options)");
                columns = 76 / width;
                if (columns == 0)
                        columns = 1;
                lines = (NCMDS + columns - 1) / columns;
                for (i = 0; i < lines; i++) {
-                       b = printf("   ");
+                       b = printf("    ");
                        total_bytes += b;
                        total_bytes_out += b;
                        for (j = 0; j < columns; j++) {
@@ -1432,16 +1433,22 @@
                                w = strlen(c->name);
                                if (! c->implemented) {
                                        putchar('-');
+                                       total_bytes++;
+                                       total_bytes_out++;
                                        w++;
                                }
                                if (c->hasopts) {
                                        putchar('+');
+                                       total_bytes++;
+                                       total_bytes_out++;
                                        w++;
                                }
                                if (c + lines >= &ctab[NCMDS])
                                        break;
                                while (w < width) {
                                        putchar(' ');
+                                       total_bytes++;
+                                       total_bytes_out++;
                                        w++;
                                }
                        }
diff -r abcb588dbbd3 -r bc871442f4e4 libexec/ftpd/ftpd.c
--- a/libexec/ftpd/ftpd.c       Tue May 18 07:51:34 1999 +0000
+++ b/libexec/ftpd/ftpd.c       Tue May 18 08:14:17 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftpd.c,v 1.62 1999/05/17 15:14:54 lukem Exp $  */
+/*     $NetBSD: ftpd.c,v 1.63 1999/05/18 08:14:18 lukem Exp $  */
 
 /*
  * Copyright (c) 1985, 1988, 1990, 1992, 1993, 1994
@@ -80,7 +80,7 @@
 #if 0
 static char sccsid[] = "@(#)ftpd.c     8.5 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: ftpd.c,v 1.62 1999/05/17 15:14:54 lukem Exp $");
+__RCSID("$NetBSD: ftpd.c,v 1.63 1999/05/18 08:14:18 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -231,6 +231,7 @@
 int    klogin __P((struct passwd *, char *, char *, char *));
 void   kdestroy __P((void));
 #endif
+
 int
 main(argc, argv)
        int argc;
@@ -355,10 +356,11 @@
 
        /* If logins are disabled, print out the message. */
        if ((fd = fopen(_PATH_NOLOGIN,"r")) != NULL) {
+               lreply(530, "");
                while (fgets(line, sizeof(line), fd) != NULL) {
                        if ((cp = strchr(line, '\n')) != NULL)
                                *cp = '\0';
-                       lreply(530, "%s", line);
+                       lreply(0, "%s", line);
                }
                (void) fflush(stdout);
                (void) fclose(fd);
@@ -366,10 +368,11 @@
                exit(0);
        }
        if ((fd = fopen(conffilename(_PATH_FTPWELCOME), "r")) != NULL) {
+               lreply(220, "");
                while (fgets(line, sizeof(line), fd) != NULL) {
                        if ((cp = strchr(line, '\n')) != NULL)
                                *cp = '\0';
-                       lreply(220, "%s", line);
+                       lreply(0, "%s", line);
                }
                (void) fflush(stdout);
                (void) fclose(fd);
@@ -751,10 +754,11 @@
        if ((fd = fopen(conffilename(_PATH_FTPLOGINMESG), "r")) != NULL) {
                char *cp, line[LINE_MAX];
 
+               lreply(230, "");
                while (fgets(line, sizeof(line), fd) != NULL) {
                        if ((cp = strchr(line, '\n')) != NULL)
                                *cp = '\0';
-                       lreply(230, "%s", line);
+                       lreply(0, "%s", line);
                }
                (void) fflush(stdout);
                (void) fclose(fd);
@@ -797,13 +801,13 @@
        FILE *fin = NULL, *dout;
        struct stat st;
        int (*closefunc) __P((FILE *)) = NULL;
-       int log, sendrv, closerv, stderrfd, isconversion, isdata;
+       int log, sendrv, closerv, stderrfd, isconversion, isdata, isls;
        struct timeval start, finish, td, *tdp;
        char tline[BUFSIZ];
        const char *dispname;
 
        sendrv = closerv = stderrfd = -1;
-       isconversion = isdata = log = 0;
+       isconversion = isdata = isls = log = 0;
        tdp = NULL;
        dispname = name;
        if (cmd == NULL) {
@@ -821,11 +825,17 @@
        if (cmd != NULL) {
                char temp[MAXPATHLEN + 1];
 
-               (void)snprintf(temp, sizeof(temp), "%s", TMPFILE);
-               stderrfd = mkstemp(temp);
-               if (stderrfd != -1)
-                       (void)unlink(temp);
-               (void)snprintf(tline, sizeof(tline), "%s", cmd);
+               if (strncmp(cmd, INTERNAL_LS, sizeof(INTERNAL_LS) - 1) == 0 &&
+                   strchr(" \t\n", cmd[sizeof(INTERNAL_LS) - 1]) != NULL) {
+                       isls = 1;
+                       stderrfd = -1;
+               } else {
+                       (void)snprintf(temp, sizeof(temp), "%s", TMPFILE);
+                       stderrfd = mkstemp(temp);
+                       if (stderrfd != -1)
+                               (void)unlink(temp);
+               }
+               (void)snprintf(tline, sizeof(tline), cmd, name);
                dispname = tline;
                fin = ftpd_popen(tline, "r", stderrfd);
                closefunc = ftpd_pclose;
@@ -887,7 +897,7 @@
                FILE *err;
                struct stat sb;
 
-               if (cmd != NULL && closerv != 0) {
+               if (!isls && cmd != NULL && closerv != 0) {
                        lreply(226,
                            "Command returned an exit status of %d",
                            closerv);
@@ -896,7 +906,7 @@
                                    "get command: '%s' returned %d",
                                    cmd, closerv);
                }
-               if (cmd != NULL && stderrfd != -1 &&
+               if (!isls && cmd != NULL && stderrfd != -1 &&
                    (fstat(stderrfd, &sb) == 0) && sb.st_size > 0 &&
                    ((err = fdopen(stderrfd, "r")) != NULL)) {
                        char *cp, line[LINE_MAX];
@@ -906,11 +916,10 @@
                        while (fgets(line, sizeof(line), err) != NULL) {
                                if ((cp = strchr(line, '\n')) != NULL)
                                        *cp = '\0';
-                               lreply(226, " %s", line);
+                               lreply(0, "  %s", line);
                        }
                        (void) fflush(stdout);
                        (void) fclose(err);
-                       lreply(226, "End of command error messages.");
                                /* a reply(226,) must follow */
                }
                reply(226, "Transfer complete.");
@@ -1142,18 +1151,24 @@
                (void) alarm(curclass.timeout);
                while ((c = getc(instr)) != EOF) {
                        byte_count++;
+                       if (c == '\n') {
+                               if (ferror(outstr))
+                                       goto data_err;
+                               (void) putc('\r', outstr);
+                               if (isdata) {
+                                       total_data_out++;
+                                       total_data++;
+                               }
+                               total_bytes_out++;
+                               total_bytes++;
+                       }
+                       (void) putc(c, outstr);
                        if (isdata) {
                                total_data_out++;
                                total_data++;
                        }



Home | Main Index | Thread Index | Old Index