Subject: reply2.patch

From: Kev <[email-masked]>
Date: Wed, 26 Nov 1997 09:30:07 EST

I sent the reply patch in, then remembered that I had wanted to change the
(v)sprintf() calls to use (v)snprintf().  This patch makes that change, and
as an added bonus, changes all the printf()'s and putc()'s that I could
find to redirect through lreply(0,...) as appropriate.

------ Patch begins ------
Index: wu-ftpd/src/ftpcmd.y
diff -u wu-ftpd/src/ftpcmd.y:1.1.1.2 wu-ftpd/src/ftpcmd.y:1.2
--- wu-ftpd/src/ftpcmd.y:1.1.1.2	Mon Sep 15 21:54:05 1997
+++ wu-ftpd/src/ftpcmd.y	Tue Nov 25 13:23:17 1997
@@ -1454,20 +1454,27 @@
             columns = 1;
         lines = (NCMDS + columns - 1) / columns;
         for (i = 0; i < lines; i++) {
-            printf("   ");
+	    char line[BUFSIZ], *ptr = line;
+
+            /*printf("   ");*/
+	    strcpy(ptr, "   ");
+	    ptr += 3;
             for (j = 0; j < columns; j++) {
                 c = ctab + j * lines + i;
-                printf("%s%c", c->name,
-                    c->implemented ? ' ' : '*');
+                ptr += sprintf(ptr, "%s%c", c->name,
+			       c->implemented ? ' ' : '*');
                 if (c + lines >= &ctab[NCMDS])
                     break;
                 w = strlen(c->name) + 1;
                 while (w < width) {
-                    putc(' ',stdout);
+		    /*putc(' ',stdout);*/
+		    *(ptr++) = ' ';
                     w++;
                 }
             }
-            printf("\r\n");
+            /*printf("\r\n");*/
+	    *ptr = '\0';
+	    lreply(0, "%s", line);
         }
         (void) fflush(stdout);
         if ( (getaclentry("email", &entry)) && ARG0 )
@@ -1618,7 +1625,7 @@
     lreply(214, "The following aliases are available.");
 
     while (getaclentry("alias", &entry) && ARG0 && ARG1 != NULL)
-        printf ("   %-8s %s\r\n", ARG0, ARG1);
+        lreply (0, "   %-8s %s", ARG0, ARG1);
     (void) fflush (stdout);
 
     reply(214, "");
@@ -1630,7 +1637,7 @@
 
     lreply(214, "The cdpath is:");
     while (getaclentry("cdpath", &entry) && ARG0 != NULL)
-        printf ("  %s\r\n", ARG0);
+        lreply (0, "  %s", ARG0);
     (void) fflush (stdout);
     reply(214, "");
 }
Index: wu-ftpd/src/ftpd.c
diff -u wu-ftpd/src/ftpd.c:1.2 wu-ftpd/src/ftpd.c:1.4
--- wu-ftpd/src/ftpd.c:1.2	Fri Oct 31 16:23:31 1997
+++ wu-ftpd/src/ftpd.c	Wed Nov 26 09:00:51 1997
@@ -2554,7 +2554,7 @@
         transflag = 0;
         if (bare_lfs) {
             lreply(226, "WARNING! %d bare linefeeds received in ASCII mode", bare_lfs);
-            printf("   File may not have transferred correctly.\r\n");
+            lreply(0, "   File may not have transferred correctly.");
         }
         return (0);
     default:
@@ -2582,7 +2582,7 @@
 char *filename;
 #endif
 {
-    char line[BUFSIZ];
+    char line[BUFSIZ], *ptr;
     FILE *fin;
     int c;
 
@@ -2592,13 +2592,14 @@
         (void) snprintf(line, sizeof(line), ls_short, filename);
     fin = ftpd_popen(line, "r", 0);
     lreply(213, "status of %s:", filename);
+    /*
     while ((c = getc(fin)) != EOF) {
         if (c == '\n') {
             if (ferror(stdout)) {
                 perror_reply(421, "control connection");
                 (void) ftpd_pclose(fin);
                 dologout(1);
-                /* NOTREACHED */
+                / * NOTREACHED * /
             }
             if (ferror(fin)) {
                 perror_reply(551, filename);
@@ -2609,6 +2610,12 @@
         }
         (void) putc(c, stdout);
     }
+    */
+    while (fgets(line, sizeof(line), fin) != NULL) {
+        if ((ptr = strchr(line, '\n'))) /* clip out unnecessary newline */
+            *ptr = '\0';
+	lreply(0, "%s", line);
+    }
     (void) ftpd_pclose(fin);
     reply(213, "End of Status");
 }
@@ -2625,20 +2632,37 @@
      *p;
 
     lreply(211, "%s FTP server status:", hostname);
-    printf("     %s\r\n", version);
-    printf("     Connected to %s", remotehost);
+    lreply(0, "     %s", version);
     if (!isdigit(remotehost[0]))
-        printf(" (%s)", inet_ntoa(his_addr.sin_addr));
-    printf("\r\n");
+        lreply(0, "     Connected to %s (%s)", remotehost,
+	       inet_ntoa(his_addr.sin_addr));
+    else
+        lreply(0, "     Connected to %s", remotehost);
+
     if (logged_in) {
         if (anonymous)
-            printf("     Logged in anonymously\r\n");
+            lreply(0, "     Logged in anonymously");
         else
-            printf("     Logged in as %s\r\n", pw->pw_name);
+            lreply(0, "     Logged in as %s", pw->pw_name);
     } else if (askpasswd)
-        printf("     Waiting for password\r\n");
+        lreply(0, "     Waiting for password");
+    else
+        lreply(0, "     Waiting for user name");
+
+    if (type == TYPE_L)
+#ifdef NBBY
+        lreply(0, "     TYPE: %s %d; STRUcture: %s; transfer MODE: %s",
+	       typenames[type], NBBY, strunames[stru], modenames[mode]);
+#else
+        lreply(0, "     TYPE: %s %d; STRUcture: %s; transfer MODE: %s",
+	       typenames[type], bytesize, strunames[stru], modenames[mode]);
+#endif /* NBBY */
     else
-        printf("     Waiting for user name\r\n");
+        lreply(0, "     TYPE: %s%s%s; STRUcture: %s; transfer MODE: %s",
+	       typenames[type], (type == TYPE_A || type == TYPE_E) ?
+	       ", FORM: " : "", (type == TYPE_A || type == TYPE_E) ?
+	       formnames[form] : "", strunames[stru], modenames[mode]);
+    /*
     printf("     TYPE: %s", typenames[type]);
     if (type == TYPE_A || type == TYPE_E)
         printf(", FORM: %s", formnames[form]);
@@ -2646,12 +2670,20 @@
 #ifdef NBBY 
         printf(" %d", NBBY);
 #else
-        printf(" %d", bytesize);/* need definition! */
+        printf(" %d", bytesize);/ * need definition! * /
 #endif
     printf("; STRUcture: %s; transfer MODE: %s\r\n",
            strunames[stru], modenames[mode]);
+	   */
     if (data != -1)
-        printf("     Data connection open\r\n");
+        lreply(0, "     Data connection open");
+    else if (pdata != -1 || usedefault == 0)
+#define UC(b) (((int) b) & 0xff)
+      lreply(0, "     %s (%d,%d,%d,%d,%d,%d)",
+	     usedefault == 0 ? "PORT" : "in Passive mode",
+	     UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]), UC(p[0]), UC(p[1]));
+#undef UC
+    /*
     else if (pdata != -1) {
         printf("     in Passive mode");
         sin = &pasv_addr;
@@ -2666,8 +2698,9 @@
         printf(" (%d,%d,%d,%d,%d,%d)\r\n", UC(a[0]),
                UC(a[1]), UC(a[2]), UC(a[3]), UC(p[0]), UC(p[1]));
 #undef UC
-    } else
-        printf("     No data connection\r\n");
+    } */
+    else
+        lreply(0, "     No data connection");
     reply(211, "End of status");
 }
 
@@ -2704,15 +2737,15 @@
   flags &= USE_REPLY_NOTFMT | USE_REPLY_LONG;
 
   if (n) /* if numeric is 0, don't output one; use n==0 in place of printf's */
-    sprintf(buf, "%d%c", n, flags & USE_REPLY_LONG ? '-' : ' ');
+    sprintf(buf, "%03d%c", n, flags & USE_REPLY_LONG ? '-' : ' ');
 
   /* This is somewhat of a kludge for autospout.  I personally think that
    * autospout should be done differently, but that's not my department. -Kev
    */
   if (flags & USE_REPLY_NOTFMT)
-    sprintf(buf + (n ? 4 : 0), "%s", fmt);
+    snprintf(buf + (n ? 4 : 0), n ? sizeof(buf) - 4 : sizeof(buf), "%s", fmt);
   else
-    vsprintf(buf + (n ? 4 : 0), fmt, ap);
+    vsnprintf(buf + (n ? 4 : 0), n ? sizeof(buf) - 4 : sizeof(buf), fmt, ap);
 
   if (debug) /* debugging output :) */
     syslog(LOG_DEBUG, "<--- %s", buf);

-- 
Kevin L. Mitchell                                            [email-masked]
-------------------------  -. .---- --.. ..- -..-  -------------------------
MIT Kerberos Development Team                           Work: (617) 253-9483
http://web.mit.edu/klmitch/www/              PGP keys available upon request