cvs commit: src/libexec/lukemftpd Makefile
Garrett Wollman
wollman at khavrinen.lcs.mit.edu
Wed Sep 10 12:45:19 PDT 2003
<<On Wed, 10 Sep 2003 12:03:48 -0700 (PDT), "David E. O'Brien" <obrien at FreeBSD.org> 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);
More information about the cvs-src
mailing list