Source-Changes-HG archive

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

[src/trunk]: src/libexec/ftpd Use sysconf(_SC_LOGIN_NAME_MAX) to determine th...



details:   https://anonhg.NetBSD.org/src/rev/cfd0251bcffb
branches:  trunk
changeset: 556221:cfd0251bcffb
user:      lukem <lukem%NetBSD.org@localhost>
date:      Wed Dec 10 01:18:56 2003 +0000

description:
Use sysconf(_SC_LOGIN_NAME_MAX) to determine the length of login
names, rather than assuming LOGIN_NAME_MAX.
Based on patch from Garrett Wollman via David O'Brien (both at FreeBSD.org)

diffstat:

 libexec/ftpd/ftpd.c    |  27 +++++++++++++++++++++++----
 libexec/ftpd/version.h |   4 ++--
 2 files changed, 25 insertions(+), 6 deletions(-)

diffs (85 lines):

diff -r d9f31dc24365 -r cfd0251bcffb libexec/ftpd/ftpd.c
--- a/libexec/ftpd/ftpd.c       Wed Dec 10 00:24:21 2003 +0000
+++ b/libexec/ftpd/ftpd.c       Wed Dec 10 01:18:56 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ftpd.c,v 1.156 2003/08/07 09:46:39 agc Exp $   */
+/*     $NetBSD: ftpd.c,v 1.157 2003/12/10 01:18:56 lukem Exp $ */
 
 /*
  * Copyright (c) 1997-2003 The NetBSD Foundation, Inc.
@@ -105,7 +105,7 @@
 #if 0
 static char sccsid[] = "@(#)ftpd.c     8.5 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: ftpd.c,v 1.156 2003/08/07 09:46:39 agc Exp $");
+__RCSID("$NetBSD: ftpd.c,v 1.157 2003/12/10 01:18:56 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -196,6 +196,9 @@
 static const char *anondir = NULL;
 static const char *confdir = _DEFAULT_CONFDIR;
 
+static char    *curname;               /* current USER name */
+static size_t  curname_len;            /* length of curname (include NUL) */
+
 #if defined(KERBEROS) || defined(KERBEROS5)
 int    has_ccache = 0;
 int    notickets = 1;
@@ -413,6 +416,23 @@
        if (EMPTYSTR(confdir))
                confdir = _DEFAULT_CONFDIR;
 
+       errno = 0;
+       l = sysconf(_SC_LOGIN_NAME_MAX);
+       if (l == -1 && errno != 0) {
+               syslog(LOG_ERR, "sysconf _SC_LOGIN_NAME_MAX: %m");
+               exit(1);
+       } else if (l <= 0) {
+               syslog(LOG_WARNING, "using conservative LOGIN_NAME_MAX value");
+               curname_len = _POSIX_LOGIN_NAME_MAX;
+       } else 
+               curname_len = (size_t)l;
+       curname = malloc(curname_len);
+       if (curname == NULL) {
+               syslog(LOG_ERR, "malloc: %m");
+               exit(1);
+       }
+       curname[0] = '\0';
+
        memset((char *)&his_addr, 0, sizeof(his_addr));
        addrlen = sizeof(his_addr.si_su);
        if (getpeername(0, (struct sockaddr *)&his_addr.si_su, &addrlen) < 0) {
@@ -609,7 +629,6 @@
 static int     login_attempts; /* number of failed login attempts */
 static int     askpasswd;      /* had USER command, ask for PASSwd */
 static int     permitted;      /* USER permitted */
-static char    curname[LOGIN_NAME_MAX];        /* current USER name */
 
 /*
  * USER command.
@@ -683,7 +702,7 @@
        } else
                pw = sgetpwnam(name);
 
-       strlcpy(curname, name, sizeof(curname));
+       strlcpy(curname, name, curname_len);
 
                        /* check user in /etc/ftpusers, and setup class */
        permitted = checkuser(_PATH_FTPUSERS, curname, 1, 0, &class);
diff -r d9f31dc24365 -r cfd0251bcffb libexec/ftpd/version.h
--- a/libexec/ftpd/version.h    Wed Dec 10 00:24:21 2003 +0000
+++ b/libexec/ftpd/version.h    Wed Dec 10 01:18:56 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: version.h,v 1.55 2003/06/30 03:06:06 tacha Exp $       */
+/*     $NetBSD: version.h,v 1.56 2003/12/10 01:18:56 lukem Exp $       */
 /*-
  * Copyright (c) 1999-2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -36,5 +36,5 @@
  */
 
 #ifndef FTPD_VERSION
-#define        FTPD_VERSION    "NetBSD-ftpd 20030630"
+#define        FTPD_VERSION    "NetBSD-ftpd 20031210"
 #endif



Home | Main Index | Thread Index | Old Index