Source-Changes-HG archive

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

[src/trunk]: src/libexec/ftpd - move password checking into separate valid_pa...



details:   https://anonhg.NetBSD.org/src/rev/b01ef650d024
branches:  trunk
changeset: 499809:b01ef650d024
user:      lukem <lukem%NetBSD.org@localhost>
date:      Thu Nov 30 02:59:11 2000 +0000

description:
- move password checking into separate valid_passwd() function, to assist
  in porting to other systems.
- don't syslog() or setproctitle() "ACCT" lines (as per "PASS")
- replace #ifdef HASSETPROCTITLE with #if HAVE_SETPROCTITLE, and set the
  latter #ifdef BSD4_4
- don't compile in internal `ls' #ifdef NO_INTERNAL_LS. will need Makefile
  support if this is to be used on NetBSD.

diffstat:

 libexec/ftpd/Makefile  |   5 ++---
 libexec/ftpd/extern.h  |   5 +++--
 libexec/ftpd/ftpcmd.y  |  18 ++++++++++--------
 libexec/ftpd/ftpd.c    |  42 ++++++++++++++++++++++++++++++++----------
 libexec/ftpd/popen.c   |   9 +++++++--
 libexec/ftpd/version.h |   4 ++--
 6 files changed, 56 insertions(+), 27 deletions(-)

diffs (257 lines):

diff -r 352de1e8cb41 -r b01ef650d024 libexec/ftpd/Makefile
--- a/libexec/ftpd/Makefile     Thu Nov 30 02:55:50 2000 +0000
+++ b/libexec/ftpd/Makefile     Thu Nov 30 02:59:11 2000 +0000
@@ -1,10 +1,9 @@
-#      $NetBSD: Makefile,v 1.43 2000/07/03 03:34:25 matt Exp $
+#      $NetBSD: Makefile,v 1.44 2000/11/30 02:59:11 lukem Exp $
 #      @(#)Makefile    8.2 (Berkeley) 4/4/94
 
 PROG=  ftpd
 SRCS=  cmds.c conf.c ftpd.c ftpcmd.y logutmp.c logwtmp.c popen.c
-CPPFLAGS+=-DHASSETPROCTITLE -I${.CURDIR}
-# CPPFLAGS+=-DDEBUG            # XXX for lukem testing
+CPPFLAGS+=-I${.CURDIR}
 DPADD+=        ${LIBCRYPT} ${LIBUTIL}
 LDADD+=        -lcrypt -lutil
 MAN=   ftpd.conf.5 ftpusers.5 ftpd.8
diff -r 352de1e8cb41 -r b01ef650d024 libexec/ftpd/extern.h
--- a/libexec/ftpd/extern.h     Thu Nov 30 02:55:50 2000 +0000
+++ b/libexec/ftpd/extern.h     Thu Nov 30 02:59:11 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.35 2000/11/16 13:15:13 lukem Exp $        */
+/*     $NetBSD: extern.h,v 1.36 2000/11/30 02:59:11 lukem Exp $        */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -239,6 +239,7 @@
 #include <netinet/in.h>
 
 #ifdef BSD4_4
+# define HAVE_SETPROCTITLE     1
 # define HAVE_SOCKADDR_SA_LEN  1
 #endif
 
@@ -296,7 +297,7 @@
 GLOBAL int             logged_in;
 GLOBAL int             logging;
 GLOBAL int             pdata;                  /* for passive mode */
-#ifdef HASSETPROCTITLE
+#if HAVE_SETPROCTITLE
 GLOBAL char            proctitle[BUFSIZ];      /* initial part of title */
 #endif
 GLOBAL struct passwd  *pw;
diff -r 352de1e8cb41 -r b01ef650d024 libexec/ftpd/ftpcmd.y
--- a/libexec/ftpd/ftpcmd.y     Thu Nov 30 02:55:50 2000 +0000
+++ b/libexec/ftpd/ftpcmd.y     Thu Nov 30 02:59:11 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftpcmd.y,v 1.57 2000/11/28 09:31:29 lukem Exp $        */
+/*     $NetBSD: ftpcmd.y,v 1.58 2000/11/30 02:59:11 lukem Exp $        */
 
 /*-
  * Copyright (c) 1997-2000 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.57 2000/11/28 09:31:29 lukem Exp $");
+__RCSID("$NetBSD: ftpcmd.y,v 1.58 2000/11/30 02:59:11 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -1383,10 +1383,11 @@
                return (NULL);
        *cs++ = '\0';
        if (debug) {
-               if (curclass.type != CLASS_GUEST &&
-                   strncasecmp("pass ", s, 5) == 0) {
+               if ((curclass.type != CLASS_GUEST &&
+                   strncasecmp(s, "PASS ", 5) == 0) ||
+                   strncasecmp(s, "ACCT ", 5) == 0) {
                        /* Don't syslog passwords */
-                       syslog(LOG_DEBUG, "command: %.5s ???", s);
+                       syslog(LOG_DEBUG, "command: %.4s ???", s);
                } else {
                        char *cp;
                        int len;
@@ -1439,10 +1440,11 @@
                (void) alarm(0);
                if ((cp = strchr(cbuf, '\r'))) {
                        *cp = '\0';
-#ifdef HASSETPROCTITLE
-                       if (strncasecmp(cbuf, "PASS", 4) != 0)
+#if HAVE_SETPROCTITLE
+                       if (strncasecmp(cbuf, "PASS", 4) != 0 &&
+                           strncasecmp(cbuf, "ACCT", 4) != 0)
                                setproctitle("%s: %s", proctitle, cbuf);
-#endif /* HASSETPROCTITLE */
+#endif /* HAVE_SETPROCTITLE */
                        *cp++ = '\n';
                        *cp = '\0';
                }
diff -r 352de1e8cb41 -r b01ef650d024 libexec/ftpd/ftpd.c
--- a/libexec/ftpd/ftpd.c       Thu Nov 30 02:55:50 2000 +0000
+++ b/libexec/ftpd/ftpd.c       Thu Nov 30 02:59:11 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftpd.c,v 1.114 2000/11/28 09:46:34 lukem Exp $ */
+/*     $NetBSD: ftpd.c,v 1.115 2000/11/30 02:59:11 lukem Exp $ */
 
 /*
  * Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
@@ -109,7 +109,7 @@
 #if 0
 static char sccsid[] = "@(#)ftpd.c     8.5 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: ftpd.c,v 1.114 2000/11/28 09:46:34 lukem Exp $");
+__RCSID("$NetBSD: ftpd.c,v 1.115 2000/11/30 02:59:11 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -218,6 +218,7 @@
 static void     myoob(int);
 static int      receive_data(FILE *, FILE *);
 static int      send_data(FILE *, FILE *, off_t, int);
+static int      valid_passwd(const struct passwd *, const char *);
 static struct passwd *sgetpwnam(const char *);
 
 int    main(int, char *[]);
@@ -864,8 +865,7 @@
                        }
                }
 #endif
-               if (!sflag && *pw->pw_passwd != '\0' &&
-                   !strcmp(crypt(passwd, pw->pw_passwd), pw->pw_passwd)) {
+               if (!sflag && valid_passwd(pw, passwd)) {
                        rval = 0;
                        goto skip;
                }
@@ -1104,13 +1104,13 @@
        show_chdir_messages(230);
        if (curclass.type == CLASS_GUEST) {
                reply(230, "Guest login ok, access restrictions apply.");
-#ifdef HASSETPROCTITLE
+#if HAVE_SETPROCTITLE
                snprintf(proctitle, sizeof(proctitle),
                    "%s: anonymous/%.*s", remotehost,
                    (int) (sizeof(proctitle) - sizeof(remotehost) -
                    sizeof(": anonymous/")), passwd);
                setproctitle("%s", proctitle);
-#endif /* HASSETPROCTITLE */
+#endif /* HAVE_SETPROCTITLE */
                if (logging)
                        syslog(LOG_INFO,
                        "ANONYMOUS FTP LOGIN FROM %s, %s (class: %s, type: %s)",
@@ -1118,11 +1118,11 @@
                            curclass.classname, CURCLASSTYPE);
        } else {
                reply(230, "User %s logged in.", pw->pw_name);
-#ifdef HASSETPROCTITLE
+#if HAVE_SETPROCTITLE
                snprintf(proctitle, sizeof(proctitle),
                    "%s: %s", remotehost, pw->pw_name);
                setproctitle("%s", proctitle);
-#endif /* HASSETPROCTITLE */
+#endif /* HAVE_SETPROCTITLE */
                if (logging)
                        syslog(LOG_INFO,
                            "FTP LOGIN FROM %s as %s (class: %s, type: %s)",
@@ -2110,10 +2110,10 @@
            who->su_len, remotehost, sizeof(remotehost), NULL, 0, 0))
                strlcpy(remotehost, "?", sizeof(remotehost));
 
-#ifdef HASSETPROCTITLE
+#if HAVE_SETPROCTITLE
        snprintf(proctitle, sizeof(proctitle), "%s: connected", remotehost);
        setproctitle("%s", proctitle);
-#endif /* HASSETPROCTITLE */
+#endif /* HAVE_SETPROCTITLE */
        if (logging)
                syslog(LOG_INFO, "connection from %s to %s",
                    remotehost, hostname);
@@ -2776,6 +2776,28 @@
        syslog(LOG_INFO, "%s", buf);
 }
 
+/*
+ * determine if password is valid for user given in pw
+ * returns 1 if ok, 0 if not.
+ */
+int
+valid_passwd(const struct passwd *pw, const char *password)
+{
+       char *orig, *new;
+       int rv;
+
+                       /* save existing password */
+       orig = pw->pw_passwd;
+                       /* don't let people without passwords in */
+       if (orig[0] == '\0')
+               return 0;
+                       /* encrypt given password */
+       new = crypt(password, orig);
+                       /* compare */
+       rv = strcmp(new, orig) == 0;
+       return (rv);
+}
+
 char *
 xstrdup(const char *s)
 {
diff -r 352de1e8cb41 -r b01ef650d024 libexec/ftpd/popen.c
--- a/libexec/ftpd/popen.c      Thu Nov 30 02:55:50 2000 +0000
+++ b/libexec/ftpd/popen.c      Thu Nov 30 02:59:11 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: popen.c,v 1.22 2000/05/20 23:34:55 lukem Exp $ */
+/*     $NetBSD: popen.c,v 1.23 2000/11/30 02:59:11 lukem Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
 #if 0
 static char sccsid[] = "@(#)popen.c    8.3 (Berkeley) 4/6/94";
 #else
-__RCSID("$NetBSD: popen.c,v 1.22 2000/05/20 23:34:55 lukem Exp $");
+__RCSID("$NetBSD: popen.c,v 1.23 2000/11/30 02:59:11 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -163,7 +163,9 @@
        if (sl_add(sl, NULL) == -1)
                goto pfree;
 
+#ifndef NO_INTERNAL_LS
        isls = (strcmp(sl->sl_str[0], INTERNAL_LS) == 0);
+#endif
 
        pid = isls ? fork() : vfork();
        switch (pid) {
@@ -190,11 +192,14 @@
                        }
                        (void)close(pdes[1]);
                }
+#ifndef NO_INTERNAL_LS
                if (isls) {     /* use internal ls */
                        optreset = optind = optopt = 1;
                        closelog();
                        exit(ls_main(sl->sl_cur - 1, sl->sl_str));
                }
+#endif
+
                execv(sl->sl_str[0], sl->sl_str);
                _exit(1);
        }
diff -r 352de1e8cb41 -r b01ef650d024 libexec/ftpd/version.h
--- a/libexec/ftpd/version.h    Thu Nov 30 02:55:50 2000 +0000
+++ b/libexec/ftpd/version.h    Thu Nov 30 02:59:11 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: version.h,v 1.24 2000/11/28 09:32:20 lukem Exp $       */
+/*     $NetBSD: version.h,v 1.25 2000/11/30 02:59:12 lukem Exp $       */
 /*-
  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -36,5 +36,5 @@
  */
 
 #ifndef FTPD_VERSION
-#define        FTPD_VERSION    "NetBSD-ftpd 20001128"
+#define        FTPD_VERSION    "NetBSD-ftpd 20001130"
 #endif



Home | Main Index | Thread Index | Old Index