From owner-cvs-all@FreeBSD.ORG Wed Sep 10 12:45:19 2003 Return-Path: Delivered-To: cvs-all@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0AB8116A4BF; Wed, 10 Sep 2003 12:45:19 -0700 (PDT) Received: from khavrinen.lcs.mit.edu (khavrinen.lcs.mit.edu [18.24.4.193]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9D31F43FBD; Wed, 10 Sep 2003 12:45:17 -0700 (PDT) (envelope-from wollman@khavrinen.lcs.mit.edu) Received: from khavrinen.lcs.mit.edu (localhost.nic.fr [IPv6:::1]) by khavrinen.lcs.mit.edu (8.12.9/8.12.9) with ESMTP id h8AJjGXV081271 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK CN=khavrinen.lcs.mit.edu issuer=SSL+20Client+20CA); Wed, 10 Sep 2003 15:45:16 -0400 (EDT) (envelope-from wollman@khavrinen.lcs.mit.edu) Received: (from wollman@localhost) by khavrinen.lcs.mit.edu (8.12.9/8.12.9/Submit) id h8AJjGD0081268; Wed, 10 Sep 2003 15:45:16 -0400 (EDT) (envelope-from wollman) Date: Wed, 10 Sep 2003 15:45:16 -0400 (EDT) From: Garrett Wollman Message-Id: <200309101945.h8AJjGD0081268@khavrinen.lcs.mit.edu> To: "David E. O'Brien" In-Reply-To: <200309101903.h8AJ3m8J016531@repoman.freebsd.org> References: <200309101903.h8AJ3m8J016531@repoman.freebsd.org> X-Spam-Score: -15.9 () IN_REP_TO,PATCH_UNIFIED_DIFF,REFERENCES X-Scanned-By: MIMEDefang 2.33 (www . roaringpenguin . com / mimedefang) cc: cvs-src@FreeBSD.org cc: src-committers@FreeBSD.org cc: cvs-all@FreeBSD.org Subject: cvs commit: src/libexec/lukemftpd Makefile X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Sep 2003 19:45:19 -0000 < said: > [commit message deleted because it was not really relevant] Here is a patch which makes lukemftpd do the POSIXly correct thing. I've tested this to the extent of compiling it. -GAWollman Index: ftpd.c =================================================================== RCS file: /home/cvs/src/contrib/lukemftpd/src/ftpd.c,v retrieving revision 1.3 diff -u -r1.3 ftpd.c --- ftpd.c 2 Feb 2003 21:03:28 -0000 1.3 +++ ftpd.c 10 Sep 2003 19:35:44 -0000 @@ -200,6 +200,15 @@ static const char *anondir = NULL; static const char *confdir = _DEFAULT_CONFDIR; +#ifdef LOGIN_NAME_MAX +static char curname[LOGIN_NAME_MAX]; +static const size_t curname_len = LOGIN_NAME_MAX; +#else +/* Sized and allocated in main() by consulting sysconf(3). */ +static char *curname; /* current USER name */ +static size_t curname_len; /* length of curname buffer */ +#endif + #if defined(KERBEROS) || defined(KERBEROS5) int has_ccache = 0; int notickets = 1; @@ -426,6 +435,26 @@ if (EMPTYSTR(confdir)) confdir = _DEFAULT_CONFDIR; +#ifndef LOGIN_NAME_MAX + errno = 0; + l = sysconf(_SC_LOGIN_NAME_MAX); + if (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, "out of memory (requested %zu bytes)", + curname_len); + exit(1); + } + curname[0] = '\0'; /* prophylaxis */ +#endif /* !LOGIN_NAME_MAX */ + 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) { @@ -612,7 +641,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. @@ -686,7 +714,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);