Source-Changes-HG archive

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

[src/trunk]: src/libexec/ftpd * move version to separate header file



details:   https://anonhg.NetBSD.org/src/rev/25b8bf55ff05
branches:  trunk
changeset: 479690:25b8bf55ff05
user:      lukem <lukem%NetBSD.org@localhost>
date:      Sat Dec 18 05:51:34 1999 +0000

description:
* move version to separate header file
* use .Dv and .Tn in the man pages as appropriate
* KNF a bit

The following were inspired by similar changes in openbsd, but may
have additional improvements by me:
* add more check_login tests to the parser rules
* nuke a few memory leaks in the parser rules
* clear passwords before free()ing them, for safety
* don't display \r\n in setproctitle() output
* add support for -U, which enables managing /var/run/utmp entries for
  connections. solves [bin/2217] by Jason Downs <downsj%teeny.org@localhost>
* fix oob handling for STAT command
* use SIG_ERR instead of -1

diffstat:

 libexec/ftpd/Makefile    |    6 +-
 libexec/ftpd/ftpcmd.y    |  350 +++++++++++++++++++++++++++-------------------
 libexec/ftpd/ftpd.8      |   60 ++++++--
 libexec/ftpd/ftpd.c      |   48 ++++-
 libexec/ftpd/ftpd.conf.5 |    9 +-
 libexec/ftpd/ftpusers.5  |    6 +-
 libexec/ftpd/logutmp.c   |  122 ++++++++++++++++
 libexec/ftpd/version.h   |   40 +++++
 8 files changed, 462 insertions(+), 179 deletions(-)

diffs (truncated from 1183 to 300 lines):

diff -r 20016227266d -r 25b8bf55ff05 libexec/ftpd/Makefile
--- a/libexec/ftpd/Makefile     Sat Dec 18 05:00:56 1999 +0000
+++ b/libexec/ftpd/Makefile     Sat Dec 18 05:51:34 1999 +0000
@@ -1,11 +1,11 @@
-#      $NetBSD: Makefile,v 1.38 1999/12/16 07:05:18 lukem Exp $
+#      $NetBSD: Makefile,v 1.39 1999/12/18 05:51:34 lukem Exp $
 #      @(#)Makefile    8.2 (Berkeley) 4/4/94
 
 SRCTOP=        ../..
 .include <bsd.crypto.mk>
 
 PROG=  ftpd
-SRCS=  conf.c ftpd.c ftpcmd.y logwtmp.c popen.c
+SRCS=  conf.c ftpd.c ftpcmd.y logutmp.c logwtmp.c popen.c
 CPPFLAGS+=-DHASSETPROCTITLE
 DPADD+=        ${LIBCRYPT} ${LIBUTIL}
 LDADD+=        -lcrypt -lutil
@@ -25,6 +25,8 @@
 LDADD+= -lskey
 .endif
 
+ftpd.o: version.h
+
 .if defined(CRYPTOPATH)
 .sinclude "${CRYPTOPATH}/libexec/ftpd/Makefile.frag"
 .endif
diff -r 20016227266d -r 25b8bf55ff05 libexec/ftpd/ftpcmd.y
--- a/libexec/ftpd/ftpcmd.y     Sat Dec 18 05:00:56 1999 +0000
+++ b/libexec/ftpd/ftpcmd.y     Sat Dec 18 05:51:34 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftpcmd.y,v 1.41 1999/12/12 14:05:54 lukem Exp $        */
+/*     $NetBSD: ftpcmd.y,v 1.42 1999/12/18 05:51:34 lukem Exp $        */
 
 /*-
  * Copyright (c) 1997-1999 The NetBSD Foundation, Inc.
@@ -83,7 +83,7 @@
 #if 0
 static char sccsid[] = "@(#)ftpcmd.y   8.3 (Berkeley) 4/6/94";
 #else
-__RCSID("$NetBSD: ftpcmd.y,v 1.41 1999/12/12 14:05:54 lukem Exp $");
+__RCSID("$NetBSD: ftpcmd.y,v 1.42 1999/12/18 05:51:34 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -201,6 +201,7 @@
        | PASS SP password CRLF
                {
                        pass($3);
+                       memset($3, 0, strlen($3));
                        free($3);
                }
 
@@ -281,6 +282,8 @@
 
        | LPRT check_login SP host_long_port4 CRLF
                {
+                       if ($2) {
+
                        /* reject invalid host_long_port4 */
                        if (data_dest.su_family != AF_INET) {
                                reply(500, "Illegal LPRT command rejected");
@@ -305,10 +308,14 @@
                                }
                                reply(200, "LPRT command successful.");
                        }
+
+                       }
                }
 
        | LPRT check_login SP host_long_port6 CRLF
                {
+                       if ($2) {
+
                        /* reject invalid host_long_port6 */
                        if (data_dest.su_family != AF_INET6) {
                                reply(500, "Illegal LPRT command rejected");
@@ -333,6 +340,8 @@
                                }
                                reply(200, "LPRT command successful.");
                        }
+
+                       }
                }
 
        | EPRT check_login SP STRING CRLF
@@ -345,6 +354,8 @@
                        struct addrinfo *res;
                        int i;
 
+                       if ($2) {
+
                        if (epsvall) {
                                reply(501, "EPRT disallowed after EPSV ALL");
                                goto eprt_done;
@@ -355,8 +366,6 @@
                                pdata = -1;
                        }
 
-                       /*XXX checks for login */
-
                        tmp = xstrdup($4);
                        p = tmp;
                        delim = p[0];
@@ -366,9 +375,8 @@
                                q = strchr(p, delim);
                                if (!q || *q != delim) {
                parsefail:
-                                       reply(500, "Invalid argument, rejected.");
-                                       if (tmp)
-                                               free(tmp);
+                                       reply(500,
+                                           "Invalid argument, rejected.");
                                        usedefault = 1;
                                        goto eprt_done;
                                }
@@ -420,12 +428,14 @@
                                        fail++;
                                switch (data_dest.su_family) {
                                case AF_INET:
-                                       fail += memcmp(&data_dest.su_sin.sin_addr,
+                                       fail += memcmp(
+                                           &data_dest.su_sin.sin_addr,
                                            &his_addr.su_sin.sin_addr,
                                            sizeof(data_dest.su_sin.sin_addr));
                                        break;
                                case AF_INET6:
-                                       fail += memcmp(&data_dest.su_sin6.sin6_addr,
+                                       fail += memcmp(
+                                           &data_dest.su_sin6.sin6_addr,
                                            &his_addr.su_sin6.sin6_addr,
                                            sizeof(data_dest.su_sin6.sin6_addr));
                                        break;
@@ -438,68 +448,78 @@
                                        return (NULL);
                                }
                        }
-                       free(tmp);
-                       tmp = NULL;
                        if (pdata >= 0) {
                                (void) close(pdata);
                                pdata = -1;
                        }
                        reply(200, "EPRT command successful.");
                eprt_done:;
+                       if (tmp != NULL)
+                               free(tmp);
+
+                       }
+                       free($4);
                }
 
        | PASV check_login CRLF
                {
-                       if (curclass.passive) {
-                               passive();
-                       } else {
-                               reply(500, "PASV mode not available.");
+                       if ($2) {
+                               if (curclass.passive)
+                                       passive();
+                               else
+                                       reply(500, "PASV mode not available.");
+                       }
+               }
+
+       | LPSV check_login CRLF
+               {
+                       if ($2) {
+                               if (epsvall)
+                                       reply(501,
+                                           "LPSV disallowed after EPSV ALL");
+                               else
+                                       long_passive("LPSV", PF_UNSPEC);
                        }
                }
 
-       | LPSV CRLF
+       | EPSV check_login SP NUMBER CRLF
                {
-                       if (epsvall)
-                               reply(501, "LPSV disallowed after EPSV ALL");
-                       else
-                               long_passive("LPSV", PF_UNSPEC);
+                       if ($2) {
+                               int pf;
+
+                               switch ($4) {
+                               case 1:
+                                       pf = PF_INET;
+                                       break;
+                               case 2:
+                                       pf = PF_INET6;
+                                       break;
+                               default:
+                                       pf = -1;        /*junk*/
+                                       break;
+                               }
+                               long_passive("EPSV", pf);
+                       }
                }
 
-       | EPSV SP NUMBER CRLF
+       | EPSV check_login SP ALL CRLF
                {
-                       int pf;
-                       switch ($3) {
-                       case 1:
-                               pf = PF_INET;
-                               break;
-                       case 2:
-                               pf = PF_INET6;
-                               break;
-                       default:
-                               pf = -1;        /*junk*/
-                               break;
-                       }
-                       long_passive("EPSV", pf);
-               }
-
-       | EPSV SP ALL CRLF
-               {
-                       if (!logged_in) {
-                               syslog(LOG_NOTICE, "long passive but not logged in");
-                               reply(503, "Login with USER first.");
-                       } else {
+                       if ($2) {
                                reply(200, "EPSV ALL command successful.");
                                epsvall++;
                        }
                }
 
-       | EPSV CRLF
+       | EPSV check_login CRLF
                {
-                       long_passive("EPSV", PF_UNSPEC);
+                       if ($2)
+                               long_passive("EPSV", PF_UNSPEC);
                }
 
-       | TYPE SP type_code CRLF
+       | TYPE check_login SP type_code CRLF
                {
+                       if ($2) {
+
                        switch (cmd_type) {
 
                        case TYPE_A:
@@ -532,31 +552,37 @@
                                UNIMPLEMENTED for NBBY != 8
 #endif /* NBBY == 8 */
                        }
-               }
-
-       | STRU SP struct_code CRLF
-               {
-                       switch ($3) {
-
-                       case STRU_F:
-                               reply(200, "STRU F ok.");
-                               break;
-
-                       default:
-                               reply(504, "Unimplemented STRU type.");
+                       
                        }
                }
 
-       | MODE SP mode_code CRLF
+       | STRU check_login SP struct_code CRLF
                {
-                       switch ($3) {
+                       if ($2) {
+                               switch ($4) {
+
+                               case STRU_F:
+                                       reply(200, "STRU F ok.");
+                                       break;
 
-                       case MODE_S:
-                               reply(200, "MODE S ok.");
-                               break;
+                               default:
+                                       reply(504, "Unimplemented STRU type.");
+                               }
+                       }
+               }
 
-                       default:
-                               reply(502, "Unimplemented MODE type.");
+       | MODE check_login SP mode_code CRLF
+               {
+                       if ($2) {
+                               switch ($4) {
+
+                               case MODE_S:
+                                       reply(200, "MODE S ok.");
+                                       break;
+
+                               default:
+                                       reply(502, "Unimplemented MODE type.");



Home | Main Index | Thread Index | Old Index