Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/ftp When using the response to SYST to decide whethe...



details:   https://anonhg.NetBSD.org/src/rev/5dfca735ae01
branches:  trunk
changeset: 785054:5dfca735ae01
user:      dsl <dsl%NetBSD.org@localhost>
date:      Tue Feb 19 23:29:15 2013 +0000

description:
When using the response to SYST to decide whether to default to 'binary'
  be a lot less specific.
Kyocera printers report "230 Linux" but really don't want text transfers
of pdf files!

diffstat:

 usr.bin/ftp/util.c |  35 +++++++++++++++--------------------
 1 files changed, 15 insertions(+), 20 deletions(-)

diffs (57 lines):

diff -r fb1a5b0220de -r 5dfca735ae01 usr.bin/ftp/util.c
--- a/usr.bin/ftp/util.c        Tue Feb 19 22:54:03 2013 +0000
+++ b/usr.bin/ftp/util.c        Tue Feb 19 23:29:15 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: util.c,v 1.157 2012/07/04 06:09:37 is Exp $    */
+/*     $NetBSD: util.c,v 1.158 2013/02/19 23:29:15 dsl Exp $   */
 
 /*-
  * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: util.c,v 1.157 2012/07/04 06:09:37 is Exp $");
+__RCSID("$NetBSD: util.c,v 1.158 2013/02/19 23:29:15 dsl Exp $");
 #endif /* not lint */
 
 /*
@@ -202,25 +202,20 @@
                        /* determine remote system type */
        if (command("SYST") == COMPLETE) {
                if (overbose) {
-                       char *cp, c;
-
-                       c = 0;
-                       cp = strchr(reply_string + 4, ' ');
-                       if (cp == NULL)
-                               cp = strchr(reply_string + 4, '\r');
-                       if (cp) {
-                               if (cp[-1] == '.')
-                                       cp--;
-                               c = *cp;
-                               *cp = '\0';
-                       }
-
-                       fprintf(ttyout, "Remote system type is %s.\n",
-                           reply_string + 4);
-                       if (cp)
-                               *cp = c;
+                       int os_len = strcspn(reply_string + 4, " \r\n\t");
+                       if (os_len > 1 && reply_string[4 + os_len - 1] == '.')
+                               os_len--;
+                       fprintf(ttyout, "Remote system type is %.*s.\n",
+                           os_len, reply_string + 4);
                }
-               if (!strncmp(reply_string, "215 UNIX Type: L8", 17)) {
+               /*
+                * Decide whether we should default to bninary.
+                * Traditionally checked for "215 UNIX Type: L8", but
+                * some printers report "Linux" ! so be more forgiving.
+                * In reality we probably almost never want text any more.
+                */
+               if (!strncasecmp(reply_string + 4, "unix", 4) ||
+                   !strncasecmp(reply_string + 4, "linux", 5)) {
                        if (proxy)
                                unix_proxy = 1;
                        else



Home | Main Index | Thread Index | Old Index